| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/storage/storage_frontend.h" | 5 #include "extensions/browser/api/storage/storage_frontend.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 16 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "extensions/browser/api/extensions_api_client.h" | 19 #include "extensions/browser/api/extensions_api_client.h" |
| 19 #include "extensions/browser/api/storage/local_value_store_cache.h" | 20 #include "extensions/browser/api/storage/local_value_store_cache.h" |
| 20 #include "extensions/browser/event_router.h" | 21 #include "extensions/browser/event_router.h" |
| 21 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
| 22 #include "extensions/browser/extension_system.h" | 23 #include "extensions/browser/extension_system.h" |
| 23 #include "extensions/browser/value_store/value_store_factory.h" | 24 #include "extensions/browser/value_store/value_store_factory.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 39 public: | 40 public: |
| 40 explicit DefaultObserver(BrowserContext* context) | 41 explicit DefaultObserver(BrowserContext* context) |
| 41 : browser_context_(context) {} | 42 : browser_context_(context) {} |
| 42 | 43 |
| 43 // SettingsObserver implementation. | 44 // SettingsObserver implementation. |
| 44 void OnSettingsChanged(const std::string& extension_id, | 45 void OnSettingsChanged(const std::string& extension_id, |
| 45 settings_namespace::Namespace settings_namespace, | 46 settings_namespace::Namespace settings_namespace, |
| 46 const std::string& change_json) override { | 47 const std::string& change_json) override { |
| 47 // TODO(gdk): This is a temporary hack while the refactoring for | 48 // TODO(gdk): This is a temporary hack while the refactoring for |
| 48 // string-based event payloads is removed. http://crbug.com/136045 | 49 // string-based event payloads is removed. http://crbug.com/136045 |
| 49 scoped_ptr<base::ListValue> args(new base::ListValue()); | 50 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 50 args->Append(base::JSONReader::Read(change_json)); | 51 args->Append(base::JSONReader::Read(change_json)); |
| 51 args->Append(new base::StringValue(settings_namespace::ToString( | 52 args->Append(new base::StringValue(settings_namespace::ToString( |
| 52 settings_namespace))); | 53 settings_namespace))); |
| 53 scoped_ptr<Event> event(new Event(events::STORAGE_ON_CHANGED, | 54 std::unique_ptr<Event> event(new Event(events::STORAGE_ON_CHANGED, |
| 54 api::storage::OnChanged::kEventName, | 55 api::storage::OnChanged::kEventName, |
| 55 std::move(args))); | 56 std::move(args))); |
| 56 EventRouter::Get(browser_context_) | 57 EventRouter::Get(browser_context_) |
| 57 ->DispatchEventToExtension(extension_id, std::move(event)); | 58 ->DispatchEventToExtension(extension_id, std::move(event)); |
| 58 } | 59 } |
| 59 | 60 |
| 60 private: | 61 private: |
| 61 BrowserContext* const browser_context_; | 62 BrowserContext* const browser_context_; |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 } // namespace | 65 } // namespace |
| 65 | 66 |
| 66 // static | 67 // static |
| 67 StorageFrontend* StorageFrontend::Get(BrowserContext* context) { | 68 StorageFrontend* StorageFrontend::Get(BrowserContext* context) { |
| 68 return BrowserContextKeyedAPIFactory<StorageFrontend>::Get(context); | 69 return BrowserContextKeyedAPIFactory<StorageFrontend>::Get(context); |
| 69 } | 70 } |
| 70 | 71 |
| 71 // static | 72 // static |
| 72 scoped_ptr<StorageFrontend> StorageFrontend::CreateForTesting( | 73 std::unique_ptr<StorageFrontend> StorageFrontend::CreateForTesting( |
| 73 const scoped_refptr<ValueStoreFactory>& storage_factory, | 74 const scoped_refptr<ValueStoreFactory>& storage_factory, |
| 74 BrowserContext* context) { | 75 BrowserContext* context) { |
| 75 return make_scoped_ptr(new StorageFrontend(storage_factory, context)); | 76 return base::WrapUnique(new StorageFrontend(storage_factory, context)); |
| 76 } | 77 } |
| 77 | 78 |
| 78 StorageFrontend::StorageFrontend(BrowserContext* context) | 79 StorageFrontend::StorageFrontend(BrowserContext* context) |
| 79 : StorageFrontend(ExtensionSystem::Get(context)->store_factory(), context) { | 80 : StorageFrontend(ExtensionSystem::Get(context)->store_factory(), context) { |
| 80 } | 81 } |
| 81 | 82 |
| 82 StorageFrontend::StorageFrontend( | 83 StorageFrontend::StorageFrontend( |
| 83 const scoped_refptr<ValueStoreFactory>& factory, | 84 const scoped_refptr<ValueStoreFactory>& factory, |
| 84 BrowserContext* context) | 85 BrowserContext* context) |
| 85 : browser_context_(context) { | 86 : browser_context_(context) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // static | 178 // static |
| 178 BrowserContextKeyedAPIFactory<StorageFrontend>* | 179 BrowserContextKeyedAPIFactory<StorageFrontend>* |
| 179 StorageFrontend::GetFactoryInstance() { | 180 StorageFrontend::GetFactoryInstance() { |
| 180 return g_factory.Pointer(); | 181 return g_factory.Pointer(); |
| 181 } | 182 } |
| 182 | 183 |
| 183 // static | 184 // static |
| 184 const char* StorageFrontend::service_name() { return "StorageFrontend"; } | 185 const char* StorageFrontend::service_name() { return "StorageFrontend"; } |
| 185 | 186 |
| 186 } // namespace extensions | 187 } // namespace extensions |
| OLD | NEW |