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

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

Issue 8497065: Extension Settings API: make it so that when leveldb storage areas fail to be (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_test_util.h" 5 #include "chrome/browser/extensions/settings/settings_test_util.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "chrome/browser/extensions/settings/settings_frontend.h"
9 #include "chrome/browser/extensions/settings/settings_storage.h"
8 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
9 11
10 namespace extensions { 12 namespace extensions {
11 13
12 namespace settings_test_util { 14 namespace settings_test_util {
13 15
14 // Intended as a StorageCallback from GetStorage. 16 // Intended as a StorageCallback from GetStorage.
15 static void AssignStorage( 17 static void AssignStorage(SettingsStorage** dst, SettingsStorage* src) {
16 SettingsStorage** dst, SettingsStorage* src) {
17 *dst = src; 18 *dst = src;
18 } 19 }
19 20
20 SettingsStorage* GetStorage( 21 SettingsStorage* GetStorage(
21 const std::string& extension_id, SettingsFrontend* frontend) { 22 const std::string& extension_id, SettingsFrontend* frontend) {
22 SettingsStorage* storage = NULL; 23 SettingsStorage* storage = NULL;
23 frontend->RunWithStorage( 24 frontend->RunWithStorage(
24 extension_id, 25 extension_id,
25 base::Bind(&AssignStorage, &storage)); 26 base::Bind(&AssignStorage, &storage));
26 MessageLoop::current()->RunAllPending(); 27 MessageLoop::current()->RunAllPending();
27 return storage; 28 return storage;
28 } 29 }
29 30
31 // MockExtesionService
32
30 MockExtensionService::MockExtensionService() {} 33 MockExtensionService::MockExtensionService() {}
31 34
32 MockExtensionService::~MockExtensionService() {} 35 MockExtensionService::~MockExtensionService() {}
33 36
34 const Extension* MockExtensionService::GetExtensionById( 37 const Extension* MockExtensionService::GetExtensionById(
35 const std::string& id, bool include_disabled) const { 38 const std::string& id, bool include_disabled) const {
36 std::map<std::string, scoped_refptr<Extension> >::const_iterator 39 std::map<std::string, scoped_refptr<Extension> >::const_iterator
37 maybe_extension = extensions_.find(id); 40 maybe_extension = extensions_.find(id);
38 return maybe_extension == extensions_.end() ? 41 return maybe_extension == extensions_.end() ?
39 NULL : maybe_extension->second.get(); 42 NULL : maybe_extension->second.get();
(...skipping 26 matching lines...) Expand all
66 extensions_[id] = Extension::CreateWithId( 69 extensions_[id] = Extension::CreateWithId(
67 FilePath(), 70 FilePath(),
68 Extension::INTERNAL, 71 Extension::INTERNAL,
69 manifest, 72 manifest,
70 Extension::NO_FLAGS, 73 Extension::NO_FLAGS,
71 id, 74 id,
72 &error); 75 &error);
73 DCHECK(error.empty()); 76 DCHECK(error.empty());
74 } 77 }
75 78
79 // MockProfile
80
76 MockProfile::MockProfile(const FilePath& file_path) 81 MockProfile::MockProfile(const FilePath& file_path)
77 : TestingProfile(file_path) { 82 : TestingProfile(file_path) {
78 event_router_.reset(new ExtensionEventRouter(this)); 83 event_router_.reset(new ExtensionEventRouter(this));
79 } 84 }
80 85
81 MockProfile::~MockProfile() {} 86 MockProfile::~MockProfile() {}
82 87
83 MockExtensionService* MockProfile::GetMockExtensionService() { 88 MockExtensionService* MockProfile::GetMockExtensionService() {
84 return &extension_service_; 89 return &extension_service_;
85 } 90 }
86 91
87 ExtensionService* MockProfile::GetExtensionService() { 92 ExtensionService* MockProfile::GetExtensionService() {
88 ExtensionServiceInterface* as_interface = 93 ExtensionServiceInterface* as_interface =
89 static_cast<ExtensionServiceInterface*>(&extension_service_); 94 static_cast<ExtensionServiceInterface*>(&extension_service_);
90 return static_cast<ExtensionService*>(as_interface); 95 return static_cast<ExtensionService*>(as_interface);
91 } 96 }
92 97
93 ExtensionEventRouter* MockProfile::GetExtensionEventRouter() { 98 ExtensionEventRouter* MockProfile::GetExtensionEventRouter() {
94 return event_router_.get(); 99 return event_router_.get();
95 } 100 }
96 101
102 // DelegatingSettingsStorageFactory
103
104 DelegatingSettingsStorageFactory::DelegatingSettingsStorageFactory(
105 SettingsStorageFactory* delegate) : delegate_(delegate) {
106 DCHECK(delegate);
107 }
108
109 DelegatingSettingsStorageFactory::~DelegatingSettingsStorageFactory() {}
110
111 void DelegatingSettingsStorageFactory::Reset(SettingsStorageFactory* delegate) {
112 DCHECK(delegate);
113 delegate_.reset(delegate);
114 }
115
116 SettingsStorage* DelegatingSettingsStorageFactory::Create(
117 const FilePath& base_path, const std::string& extension_id) {
118 return delegate_->Create(base_path, extension_id);
119 }
120
121 // NullSettingsStorageFactory
122
123 SettingsStorage* NullSettingsStorageFactory::Create(
124 const FilePath& base_path, const std::string& extension_id) {
125 return NULL;
126 }
127
97 } // namespace settings_test_util 128 } // namespace settings_test_util
98 129
99 } // namespace extensions 130 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698