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

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

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

Powered by Google App Engine
This is Rietveld 408576698