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

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: final rebase 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) 2011 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 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 }
38
39 void ExternalPrefExtensionLoader::StartLoading() {
40 CHECK(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 CHECK(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 prefs_.reset(prefs.release());
63 BrowserThread::PostTask(
64 BrowserThread::UI, FROM_HERE,
65 NewRunnableMethod(
66 this,
67 &ExternalPrefExtensionLoader::LoadFinished));
68 }
69
70 ExternalTestingExtensionLoader::ExternalTestingExtensionLoader(
71 const std::string& json_data) {
72 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
73 JSONStringValueSerializer serializer(json_data);
74 testing_prefs_.reset(ExtractPrefs(&serializer));
75 }
76
77 void ExternalTestingExtensionLoader::StartLoading() {
78 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
79 prefs_.reset(
80 static_cast<DictionaryValue*>(testing_prefs_->DeepCopy()));
81 LoadFinished();
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698