forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoped_file_access_delegate.h
69 lines (53 loc) · 2.66 KB
/
scoped_file_access_delegate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_FILE_ACCESS_SCOPED_FILE_ACCESS_DELEGATE_H_
#define COMPONENTS_FILE_ACCESS_SCOPED_FILE_ACCESS_DELEGATE_H_
#include <vector>
#include "base/callback.h"
#include "base/component_export.h"
#include "base/files/file_path.h"
#include "components/file_access/scoped_file_access.h"
#include "url/gurl.h"
class ScopedFileAccessDelegateTest;
namespace file_access {
// This class is mainly a interface and used to delegate DLP checks to
// appropriate proxy. It is used for managed ChromeOs only in the implementation
// DlpScopedfileAccessDelegate. Only one instance of a class which extends
// this class can exist at a time. The class itself also manages this one
// instance. When it is replaced the old instance is destructed.
class COMPONENT_EXPORT(FILE_ACCESS) ScopedFileAccessDelegate {
public:
ScopedFileAccessDelegate(const ScopedFileAccessDelegate&) = delete;
ScopedFileAccessDelegate& operator=(const ScopedFileAccessDelegate&) = delete;
// Returns a pointer to the existing instance of the class.
static ScopedFileAccessDelegate* Get();
// Returns true if an instance exists, without forcing an initialization.
static bool HasInstance();
// Deletes the existing instance of the class if it's already created.
// Indicates that restricting data transfer is no longer required.
// The instance will be deconstructed
static void DeleteInstance();
// Requests access to |files| in order to be sent to |destination_url|.
// |callback| is called with a token that should be hold until
// `open()` operation on the files finished.
virtual void RequestFilesAccess(
const std::vector<base::FilePath>& files,
const GURL& destination_url,
base::OnceCallback<void(file_access::ScopedFileAccess)> callback) = 0;
// Requests access to |files| in order to be sent to a system process.
// |callback| is called with a token that should be hold until
// `open()` operation on the files finished.
virtual void RequestFilesAccessForSystem(
const std::vector<base::FilePath>& files,
base::OnceCallback<void(file_access::ScopedFileAccess)> callback) = 0;
protected:
ScopedFileAccessDelegate();
virtual ~ScopedFileAccessDelegate();
// A single instance of ScopedFileAccessDelegate. Equals nullptr when there's
// not any data transfer restrictions required.
static ScopedFileAccessDelegate* scoped_file_access_delegate_;
friend class ::ScopedFileAccessDelegateTest;
};
} // namespace file_access
#endif // COMPONENTS_FILE_ACCESS_SCOPED_FILE_ACCESS_DELEGATE_H_