Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: extensions/browser/api/lock_screen_data/data_item.h

Issue 2934293003: The chrome.lockScreen.data API implementation (Closed)
Patch Set: switch to BackendTaskRunner Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/api/BUILD.gn ('k') | extensions/browser/api/lock_screen_data/data_item.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef EXTENSIONS_BROWSER_API_LOCK_SCREEN_DATA_DATA_ITEM_H_
6 #define EXTENSIONS_BROWSER_API_LOCK_SCREEN_DATA_DATA_ITEM_H_
7
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15
16 namespace content {
17 class BrowserContext;
18 }
19
20 namespace base {
21 class DictionaryValue;
22 class SequencedTaskRunner;
23 } // namespace base
24
25 namespace extensions {
26
27 class ValueStoreCache;
28
29 namespace lock_screen_data {
30
31 enum class OperationResult;
32
33 // Wrapper around a per extension value store backed lock screen data item.
34 class DataItem {
35 public:
36 using WriteCallback = base::Callback<void(OperationResult result)>;
37 using ReadCallback =
38 base::Callback<void(OperationResult result,
39 std::unique_ptr<std::vector<char>> data)>;
40 using RegisteredValuesCallback =
41 base::Callback<void(OperationResult result,
42 std::unique_ptr<base::DictionaryValue> values)>;
43
44 // Gets all registered data items for the extension with the provided
45 // extension ID - the items are returned as a DictionaryValue with keys set
46 // to data item IDs.
47 static void GetRegisteredValuesForExtension(
48 content::BrowserContext* context,
49 ValueStoreCache* value_store_cache,
50 base::SequencedTaskRunner* task_runner,
51 const std::string& extension_id,
52 const RegisteredValuesCallback& callback);
53
54 // Clears data item value store for the extension with the provided extension
55 // ID.
56 static void DeleteAllItemsForExtension(content::BrowserContext* context,
57 ValueStoreCache* value_store_cache,
58 base::SequencedTaskRunner* task_runner,
59 const std::string& extension_id,
60 const base::Closure& callback);
61
62 // |id| - Data item ID.
63 // |extension_id| - The extension that owns the item.
64 // |context| - The browser context to which the owning extension is attached.
65 // |value_store_cache| - Used to retrieve value store for the extension with
66 // |extension_id| ID. Not owned - the caller should ensure the value store
67 // cache outlives the data item. Note that DataItem post tasks with
68 // unretained |value_store_cache| to |task_runner|, which means any usage
69 // of DataItem should happen before value store cache deletion is
70 /// scheduled to |task_runner|.
71 // |task_runner| - The task runner on which value store should be used. Note
72 // that the Data item does not retain a reference to the task runner -
73 // the caller should ensure |task_runner| outlives the data item.
74 // |crypto_key| - Symmetric AES key for encrypting/decrypting data item
75 // content.
76 DataItem(const std::string& id,
77 const std::string& extension_id,
78 content::BrowserContext* context,
79 ValueStoreCache* value_store_cache,
80 base::SequencedTaskRunner* task_runner,
81 const std::string& crypto_key);
82 virtual ~DataItem();
83
84 // Registers the data item in the persistent data item storage.
85 virtual void Register(const WriteCallback& callback);
86
87 // Sets the data item content, saving it to persistent data storage.
88 // This will fail if the data item is not registered.
89 virtual void Write(const std::vector<char>& data,
90 const WriteCallback& callback);
91
92 // Gets the data item content from the persistent data storage.
93 // This will fail is the item is not registered.
94 virtual void Read(const ReadCallback& callback);
95
96 // Unregisters the data item, and clears previously persisted data item
97 // content.
98 virtual void Delete(const WriteCallback& callback);
99
100 const std::string& id() const { return id_; }
101
102 const std::string& extension_id() const { return extension_id_; }
103
104 private:
105 // Internal callback for write operations - wraps |callback| to ensure
106 // |callback| is not run after |this| has been destroyed.
107 void OnWriteDone(const WriteCallback& callback,
108 std::unique_ptr<OperationResult> result);
109
110 // Internal callback for the read operation - wraps |callback| to ensure
111 // |callback| is not run after |this| has been destroyed.
112 void OnReadDone(const ReadCallback& callback,
113 std::unique_ptr<OperationResult> result,
114 std::unique_ptr<std::vector<char>> data);
115
116 // The data item ID.
117 std::string id_;
118
119 // The ID of the extension that owns the data item.
120 std::string extension_id_;
121
122 content::BrowserContext* context_;
123
124 // Cache used to retrieve the values store to which the data item should be
125 // saved - the value stores are mapped by the extension ID.
126 ValueStoreCache* value_store_cache_;
127
128 // Task runner on which value store should be accessed.
129 base::SequencedTaskRunner* task_runner_;
130
131 // They symmetric AES key that should be used to encrypt data item content
132 // when the content is written to the storage, and to decrypt item content
133 // when reading it from the storage.
134 const std::string crypto_key_;
135
136 base::WeakPtrFactory<DataItem> weak_ptr_factory_;
137
138 DISALLOW_COPY_AND_ASSIGN(DataItem);
139 };
140
141 } // namespace lock_screen_data
142 } // namespace extensions
143
144 #endif // EXTENSIONS_BROWSER_API_LOCK_SCREEN_DATA_DATA_ITEM_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/BUILD.gn ('k') | extensions/browser/api/lock_screen_data/data_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698