Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/api/declarative/rules_registry_storage_deleg ate.h" | 5 #include "chrome/browser/extensions/api/declarative/rules_registry_storage_deleg ate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | |
| 8 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
| 9 #include "chrome/browser/extensions/state_store.h" | 10 #include "chrome/browser/extensions/state_store.h" |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
| 14 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
| 15 | 17 |
| 16 namespace extensions { | 18 namespace extensions { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 Inner(Profile* profile, | 59 Inner(Profile* profile, |
| 58 RulesRegistryWithCache* rules_registry, | 60 RulesRegistryWithCache* rules_registry, |
| 59 const std::string& storage_key); | 61 const std::string& storage_key); |
| 60 | 62 |
| 61 private: | 63 private: |
| 62 friend class base::RefCountedThreadSafe<Inner>; | 64 friend class base::RefCountedThreadSafe<Inner>; |
| 63 friend class RulesRegistryStorageDelegate; | 65 friend class RulesRegistryStorageDelegate; |
| 64 | 66 |
| 65 ~Inner(); | 67 ~Inner(); |
| 66 | 68 |
| 69 // Initialization of the storage delegate if it is used in the context of | |
| 70 // an incognito profile. | |
| 71 void InitForOTRProfile(); | |
| 72 | |
| 67 // NotificationObserver | 73 // NotificationObserver |
| 68 virtual void Observe( | 74 virtual void Observe( |
| 69 int type, | 75 int type, |
| 70 const content::NotificationSource& source, | 76 const content::NotificationSource& source, |
| 71 const content::NotificationDetails& details) OVERRIDE; | 77 const content::NotificationDetails& details) OVERRIDE; |
| 72 | 78 |
| 73 // Read/write a list of rules serialized to Values. | 79 // Read/write a list of rules serialized to Values. |
| 74 void ReadFromStorage(const std::string& extension_id); | 80 void ReadFromStorage(const std::string& extension_id); |
| 75 void ReadFromStorageCallback(const std::string& extension_id, | 81 void ReadFromStorageCallback(const std::string& extension_id, |
| 76 scoped_ptr<base::Value> value); | 82 scoped_ptr<base::Value> value); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 RulesRegistryStorageDelegate::Inner::Inner( | 163 RulesRegistryStorageDelegate::Inner::Inner( |
| 158 Profile* profile, | 164 Profile* profile, |
| 159 RulesRegistryWithCache* rules_registry, | 165 RulesRegistryWithCache* rules_registry, |
| 160 const std::string& storage_key) | 166 const std::string& storage_key) |
| 161 : registrar_(new content::NotificationRegistrar()), | 167 : registrar_(new content::NotificationRegistrar()), |
| 162 profile_(profile), | 168 profile_(profile), |
| 163 storage_key_(storage_key), | 169 storage_key_(storage_key), |
| 164 rules_registry_thread_(rules_registry->GetOwnerThread()), | 170 rules_registry_thread_(rules_registry->GetOwnerThread()), |
| 165 rules_registry_(rules_registry), | 171 rules_registry_(rules_registry), |
| 166 ready_(false) { | 172 ready_(false) { |
| 167 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 173 if (!profile_->IsOffTheRecord()) { |
| 168 content::Source<Profile>(profile)); | 174 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 169 registrar_->Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 175 content::Source<Profile>(profile)); |
| 170 content::Source<Profile>(profile)); | 176 registrar_->Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 177 content::Source<Profile>(profile)); | |
| 178 } else { | |
| 179 registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | |
| 180 content::Source<Profile>(profile)); | |
|
Matt Perry
2012/07/25 21:27:56
You need to register for the notification for prof
Yoyo Zhou
2012/07/25 21:44:45
You probably want profile->GetOriginalProfile() he
battre
2012/07/26 16:38:43
Done.
battre
2012/07/26 16:38:43
Done.
| |
| 181 InitForOTRProfile(); | |
|
Matt Perry
2012/07/25 21:27:56
You should also set ready_ = true.
battre
2012/07/26 16:38:43
I think the better approach is to call CheckIfRead
Matt Perry
2012/07/26 18:42:41
No, then it will be considered "not ready" for som
| |
| 182 } | |
| 171 } | 183 } |
| 172 | 184 |
| 173 RulesRegistryStorageDelegate::Inner::~Inner() { | 185 RulesRegistryStorageDelegate::Inner::~Inner() { |
| 174 DCHECK(!registrar_.get()); | 186 DCHECK(!registrar_.get()); |
| 175 } | 187 } |
| 176 | 188 |
| 189 void RulesRegistryStorageDelegate::Inner::InitForOTRProfile() { | |
|
Matt Perry
2012/07/25 21:27:56
May as well do this step for both types of profile
battre
2012/07/26 16:38:43
This is not quite clear to me. Note the check whet
Matt Perry
2012/07/26 18:42:41
OK, I take that back then.
| |
| 190 ExtensionService* extension_service = | |
| 191 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
| 192 const ExtensionSet* extensions = extension_service->extensions(); | |
| 193 for (ExtensionSet::const_iterator i = extensions->begin(); | |
| 194 i != extensions->end(); ++i) { | |
| 195 if ((*i)->HasAPIPermission(APIPermission::kDeclarativeWebRequest) && | |
| 196 extension_service->IsIncognitoEnabled((*i)->id())) | |
| 197 ReadFromStorage((*i)->id()); | |
| 198 } | |
| 199 } | |
| 200 | |
| 177 void RulesRegistryStorageDelegate::Inner::Observe( | 201 void RulesRegistryStorageDelegate::Inner::Observe( |
| 178 int type, | 202 int type, |
| 179 const content::NotificationSource& source, | 203 const content::NotificationSource& source, |
| 180 const content::NotificationDetails& details) { | 204 const content::NotificationDetails& details) { |
| 181 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 205 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 182 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { | 206 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { |
| 183 const extensions::Extension* extension = | 207 const extensions::Extension* extension = |
| 184 content::Details<const extensions::Extension>(details).ptr(); | 208 content::Details<const extensions::Extension>(details).ptr(); |
| 185 // TODO(mpcomplete): This API check should generalize to any use of | 209 // TODO(mpcomplete): This API check should generalize to any use of |
| 186 // declarative rules, not just webRequest. | 210 // declarative rules, not just webRequest. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 void RulesRegistryStorageDelegate::Inner::NotifyReadyOnRegistryThread() { | 270 void RulesRegistryStorageDelegate::Inner::NotifyReadyOnRegistryThread() { |
| 247 DCHECK(content::BrowserThread::CurrentlyOn(rules_registry_thread_)); | 271 DCHECK(content::BrowserThread::CurrentlyOn(rules_registry_thread_)); |
| 248 if (ready_) | 272 if (ready_) |
| 249 return; // we've already notified our readiness | 273 return; // we've already notified our readiness |
| 250 | 274 |
| 251 ready_ = true; | 275 ready_ = true; |
| 252 rules_registry_->OnReady(); | 276 rules_registry_->OnReady(); |
| 253 } | 277 } |
| 254 | 278 |
| 255 } // namespace extensions | 279 } // namespace extensions |
| OLD | NEW |