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

Side by Side Diff: chrome/browser/extensions/stateful_external_extension_provider.cc

Issue 5784004: Add DCHECKs to StatefulExternalExtensionProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase before commit Created 10 years 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
« no previous file with comments | « chrome/browser/extensions/stateful_external_extension_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/stateful_external_extension_provider.h" 5 #include "chrome/browser/extensions/stateful_external_extension_provider.h"
6 6
7 #include "app/app_paths.h" 7 #include "app/app_paths.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "base/version.h" 12 #include "base/version.h"
13 #include "chrome/browser/browser_thread.h"
13 14
14 namespace { 15 namespace {
15 16
16 // Constants for keeping track of extension preferences. 17 // Constants for keeping track of extension preferences.
17 const char kLocation[] = "location"; 18 const char kLocation[] = "location";
18 const char kState[] = "state"; 19 const char kState[] = "state";
19 const char kExternalCrx[] = "external_crx"; 20 const char kExternalCrx[] = "external_crx";
20 const char kExternalVersion[] = "external_version"; 21 const char kExternalVersion[] = "external_version";
21 const char kExternalUpdateUrl[] = "external_update_url"; 22 const char kExternalUpdateUrl[] = "external_update_url";
22 23
23 } 24 }
24 25
25 StatefulExternalExtensionProvider::StatefulExternalExtensionProvider( 26 StatefulExternalExtensionProvider::StatefulExternalExtensionProvider(
26 Extension::Location crx_location, 27 Extension::Location crx_location,
27 Extension::Location download_location) 28 Extension::Location download_location)
28 : crx_location_(crx_location), 29 : crx_location_(crx_location),
29 download_location_(download_location) { 30 download_location_(download_location) {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
30 } 32 }
31 33
32 StatefulExternalExtensionProvider::~StatefulExternalExtensionProvider() { 34 StatefulExternalExtensionProvider::~StatefulExternalExtensionProvider() {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
33 } 36 }
34 37
35 void StatefulExternalExtensionProvider::VisitRegisteredExtension( 38 void StatefulExternalExtensionProvider::VisitRegisteredExtension(
36 Visitor* visitor) const { 39 Visitor* visitor) const {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
41 DCHECK(prefs_.get());
37 for (DictionaryValue::key_iterator i = prefs_->begin_keys(); 42 for (DictionaryValue::key_iterator i = prefs_->begin_keys();
38 i != prefs_->end_keys(); ++i) { 43 i != prefs_->end_keys(); ++i) {
39 const std::string& extension_id = *i; 44 const std::string& extension_id = *i;
40 DictionaryValue* extension; 45 DictionaryValue* extension;
41 if (!prefs_->GetDictionaryWithoutPathExpansion(extension_id, &extension)) 46 if (!prefs_->GetDictionaryWithoutPathExpansion(extension_id, &extension))
42 continue; 47 continue;
43 48
44 FilePath::StringType external_crx; 49 FilePath::StringType external_crx;
45 std::string external_version; 50 std::string external_version;
46 std::string external_update_url; 51 std::string external_update_url;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 continue; 118 continue;
114 } 119 }
115 visitor->OnExternalExtensionUpdateUrlFound( 120 visitor->OnExternalExtensionUpdateUrlFound(
116 extension_id, update_url, download_location_); 121 extension_id, update_url, download_location_);
117 } 122 }
118 } 123 }
119 } 124 }
120 125
121 bool StatefulExternalExtensionProvider::HasExtension( 126 bool StatefulExternalExtensionProvider::HasExtension(
122 const std::string& id) const { 127 const std::string& id) const {
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
129 DCHECK(prefs_.get());
123 return prefs_->HasKey(id); 130 return prefs_->HasKey(id);
124 } 131 }
125 132
126 bool StatefulExternalExtensionProvider::GetExtensionDetails( 133 bool StatefulExternalExtensionProvider::GetExtensionDetails(
127 const std::string& id, Extension::Location* location, 134 const std::string& id, Extension::Location* location,
128 scoped_ptr<Version>* version) const { 135 scoped_ptr<Version>* version) const {
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
137 DCHECK(prefs_.get());
129 DictionaryValue* extension = NULL; 138 DictionaryValue* extension = NULL;
130 if (!prefs_->GetDictionary(id, &extension)) 139 if (!prefs_->GetDictionary(id, &extension))
131 return false; 140 return false;
132 141
133 Extension::Location loc = Extension::INVALID; 142 Extension::Location loc = Extension::INVALID;
134 if (extension->HasKey(kExternalUpdateUrl)) { 143 if (extension->HasKey(kExternalUpdateUrl)) {
135 loc = download_location_; 144 loc = download_location_;
136 145
137 } else if (extension->HasKey(kExternalCrx)) { 146 } else if (extension->HasKey(kExternalCrx)) {
138 loc = crx_location_; 147 loc = crx_location_;
139 148
140 std::string external_version; 149 std::string external_version;
141 if (!extension->GetString(kExternalVersion, &external_version)) 150 if (!extension->GetString(kExternalVersion, &external_version))
142 return false; 151 return false;
143 152
144 if (version) 153 if (version)
145 version->reset(Version::GetVersionFromString(external_version)); 154 version->reset(Version::GetVersionFromString(external_version));
146 155
147 } else { 156 } else {
148 NOTREACHED(); // Chrome should not allow prefs to get into this state. 157 NOTREACHED(); // Chrome should not allow prefs to get into this state.
149 return false; 158 return false;
150 } 159 }
151 160
152 if (location) 161 if (location)
153 *location = loc; 162 *location = loc;
154 163
155 return true; 164 return true;
156 } 165 }
166
167 void StatefulExternalExtensionProvider::set_prefs(DictionaryValue* prefs) {
168 prefs_.reset(prefs);
169 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/stateful_external_extension_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698