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

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

Issue 5742008: Clean up threading model of external extension providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 11 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/external_pref_extension_loader.h"
6
7 #include "app/app_paths.h"
8 #include "base/file_path.h"
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/path_service.h"
12 #include "chrome/browser/browser_thread.h"
13 #include "chrome/common/json_value_serializer.h"
14
15 namespace {
16
17 // Caller takes ownership of the returned dictionary
18 DictionaryValue* ExtractPrefs(ValueSerializer* serializer) {
19 std::string error_msg;
20 Value* extensions = serializer->Deserialize(NULL, &error_msg);
21 if (!extensions) {
22 LOG(WARNING) << "Unable to deserialize json data: " << error_msg;
23 } else {
24 if (!extensions->IsType(Value::TYPE_DICTIONARY)) {
25 NOTREACHED() << "Invalid json data";
26 } else {
27 return static_cast<DictionaryValue*>(extensions);
28 }
29 }
30 return new DictionaryValue;
31 }
32
33 } // namespace
34
35 ExternalPrefExtensionLoader::ExternalPrefExtensionLoader() {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 }
38
39 void ExternalPrefExtensionLoader::Load() {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
41 BrowserThread::PostTask(
42 BrowserThread::FILE, FROM_HERE,
43 NewRunnableMethod(
44 this,
45 &ExternalPrefExtensionLoader::LoadOnFileThread));
46 }
47
48 void ExternalPrefExtensionLoader::LoadOnFileThread() {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
50 FilePath json_file;
51 PathService::Get(app::DIR_EXTERNAL_EXTENSIONS, &json_file);
52 json_file = json_file.Append(FILE_PATH_LITERAL("external_extensions.json"));
53 scoped_ptr<DictionaryValue> prefs;
54
55 if (file_util::PathExists(json_file)) {
56 JSONFileValueSerializer serializer(json_file);
57 prefs.reset(ExtractPrefs(&serializer));
58 } else {
59 prefs.reset(new DictionaryValue());
60 }
61 {
62 AutoLock auto_(lock_);
63 prefs_.reset(prefs.release());
64 }
65 BrowserThread::PostTask(
66 BrowserThread::UI, FROM_HERE,
67 NewRunnableMethod(
68 this,
69 &ExternalPrefExtensionLoader::LoadFinished));
70 }
71
72 ExternalTestingExtensionLoader::ExternalTestingExtensionLoader(
73 const std::string& json_data) {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
75 JSONStringValueSerializer serializer(json_data);
76 testing_prefs_.reset(ExtractPrefs(&serializer));
77 }
78
79 void ExternalTestingExtensionLoader::Load() {
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
81 prefs_.reset(
82 static_cast<DictionaryValue*>(testing_prefs_->DeepCopy()));
83 LoadFinished();
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698