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

Side by Side Diff: chrome/browser/extensions/settings/settings_frontend.cc

Issue 9284013: Extension Storage API: expose storage quota information to extensions, via: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/settings/settings_frontend.h" 5 #include "chrome/browser/extensions/settings/settings_frontend.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "chrome/browser/extensions/extension_event_names.h" 9 #include "chrome/browser/extensions/extension_event_names.h"
10 #include "chrome/browser/extensions/extension_event_router.h" 10 #include "chrome/browser/extensions/extension_event_router.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/settings/settings_backend.h" 12 #include "chrome/browser/extensions/settings/settings_backend.h"
13 #include "chrome/browser/extensions/settings/settings_namespace.h" 13 #include "chrome/browser/extensions/settings/settings_namespace.h"
14 #include "chrome/browser/extensions/settings/settings_leveldb_storage.h" 14 #include "chrome/browser/extensions/settings/settings_leveldb_storage.h"
15 #include "chrome/browser/extensions/settings/weak_unlimited_settings_storage.h" 15 #include "chrome/browser/extensions/settings/weak_unlimited_settings_storage.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
19 19
20 using content::BrowserThread; 20 using content::BrowserThread;
21 21
22 namespace extensions { 22 namespace extensions {
23 23
24 namespace { 24 namespace {
25 25
26 const SettingsStorageQuotaEnforcer::Limits kSyncQuota = {
27 // 100K should be enough for simple use, but this can be increased as demand
28 // increases.
29 100 * 1024,
30
31 // Sync supports 5k per settings, so be a bit more restrictive than that.
32 2048,
33
34 // Keep low for sync.
35 512
36 };
37
38 const SettingsStorageQuotaEnforcer::Limits kLocalQuota = {
39 // Same as localStorage (5MB).
40 5 * 1000 * 1024,
41
42 // No need to be restrictive per key here.
43 UINT_MAX,
44
45 // Ditto.
46 UINT_MAX
47 };
48
49 // Settings change Observer which forwards changes on to the extension 26 // Settings change Observer which forwards changes on to the extension
50 // processes for |profile| and its incognito partner if it exists. 27 // processes for |profile| and its incognito partner if it exists.
51 class DefaultObserver : public SettingsObserver { 28 class DefaultObserver : public SettingsObserver {
52 public: 29 public:
53 explicit DefaultObserver(Profile* profile) : profile_(profile) {} 30 explicit DefaultObserver(Profile* profile) : profile_(profile) {}
54 31
55 // SettingsObserver implementation. 32 // SettingsObserver implementation.
56 virtual void OnSettingsChanged( 33 virtual void OnSettingsChanged(
57 const std::string& extension_id, 34 const std::string& extension_id,
58 settings_namespace::Namespace settings_namespace, 35 settings_namespace::Namespace settings_namespace,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 const SettingsFrontend::StorageCallback& callback, 81 const SettingsFrontend::StorageCallback& callback,
105 SettingsBackend* backend) { 82 SettingsBackend* backend) {
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
107 WeakUnlimitedSettingsStorage unlimited_storage( 84 WeakUnlimitedSettingsStorage unlimited_storage(
108 backend->GetStorage(extension_id)); 85 backend->GetStorage(extension_id));
109 callback.Run(&unlimited_storage); 86 callback.Run(&unlimited_storage);
110 } 87 }
111 88
112 } // namespace 89 } // namespace
113 90
91 // The values in kSyncQuota and kLocalQuota must match those in
92 // chrome/common/extensions/api/storage.json
93
94 // static
95 const SettingsStorageQuotaEnforcer::Limits SettingsFrontend::kSyncQuota = {
96 // 100K should be enough for simple use, but this can be increased as demand
97 // increases.
98 100 * 1024,
99
100 // Sync supports 5k per settings, so be a bit more restrictive than that.
101 2048,
102
103 // Keep low for sync.
104 512
105 };
106
107 const SettingsStorageQuotaEnforcer::Limits SettingsFrontend::kLocalQuota = {
108 // Same as localStorage (5MB).
109 5 * 1000 * 1024,
110
111 // No need to be restrictive per key here.
112 UINT_MAX,
113
114 // Ditto.
115 UINT_MAX
116 };
117
114 // Ref-counted container for a SettingsBackend object. 118 // Ref-counted container for a SettingsBackend object.
115 class SettingsFrontend::BackendWrapper 119 class SettingsFrontend::BackendWrapper
116 : public base::RefCountedThreadSafe<BackendWrapper> { 120 : public base::RefCountedThreadSafe<BackendWrapper> {
117 public: 121 public:
118 // Creates a new BackendWrapper and initializes it on the FILE thread. 122 // Creates a new BackendWrapper and initializes it on the FILE thread.
119 static scoped_refptr<BackendWrapper> CreateAndInit( 123 static scoped_refptr<BackendWrapper> CreateAndInit(
120 const scoped_refptr<SettingsStorageFactory>& factory, 124 const scoped_refptr<SettingsStorageFactory>& factory,
121 const SettingsStorageQuotaEnforcer::Limits& quota, 125 const SettingsStorageQuotaEnforcer::Limits& quota,
122 const scoped_refptr<SettingsObserverList>& observers, 126 const scoped_refptr<SettingsObserverList>& observers,
123 const FilePath& path) { 127 const FilePath& path) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
334 return observers_; 338 return observers_;
335 } 339 }
336 340
337 // BackendWrappers 341 // BackendWrappers
338 342
339 SettingsFrontend::BackendWrappers::BackendWrappers() {} 343 SettingsFrontend::BackendWrappers::BackendWrappers() {}
340 SettingsFrontend::BackendWrappers::~BackendWrappers() {} 344 SettingsFrontend::BackendWrappers::~BackendWrappers() {}
341 345
342 } // namespace extensions 346 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698