Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / default_app_order.cc
blob3f8f4ff8c372c2fe9680946dc159d9a4892a127f
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/chromeos/extensions/default_app_order.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/file_util.h"
10 #include "base/files/file_path.h"
11 #include "base/json/json_file_value_serializer.h"
12 #include "base/path_service.h"
13 #include "base/time/time.h"
14 #include "chrome/common/extensions/extension_constants.h"
15 #include "chromeos/chromeos_paths.h"
16 #include "content/public/browser/browser_thread.h"
18 namespace chromeos {
19 namespace default_app_order {
21 namespace {
23 // The single ExternalLoader instance.
24 ExternalLoader* loader_instance = NULL;
26 // Reads external ordinal json file and returned the parsed value. Returns NULL
27 // if the file does not exist or could not be parsed properly. Caller takes
28 // ownership of the returned value.
29 base::ListValue* ReadExternalOrdinalFile(const base::FilePath& path) {
30 if (!base::PathExists(path))
31 return NULL;
33 JSONFileValueSerializer serializer(path);
34 std::string error_msg;
35 base::Value* value = serializer.Deserialize(NULL, &error_msg);
36 if (!value) {
37 LOG(WARNING) << "Unable to deserialize default app ordinals json data:"
38 << error_msg << ", file=" << path.value();
39 return NULL;
42 base::ListValue* ordinal_list_value = NULL;
43 if (value->GetAsList(&ordinal_list_value))
44 return ordinal_list_value;
46 LOG(WARNING) << "Expect a JSON list in file " << path.value();
47 return NULL;
50 // Gets built-in default app order.
51 void GetDefault(std::vector<std::string>* app_ids) {
52 DCHECK(app_ids && app_ids->empty());
54 const char* kDefaultAppOrder[] = {
55 extension_misc::kChromeAppId,
56 extension_misc::kWebStoreAppId,
57 extension_misc::kGoogleSearchAppId,
58 extension_misc::kYoutubeAppId,
59 extension_misc::kGmailAppId,
60 "ejjicmeblgpmajnghnpcppodonldlgfn", // Calendar
61 "kjebfhglflhjjjiceimfkgicifkhjlnm", // Scratchpad
62 "lneaknkopdijkpnocmklfnjbeapigfbh", // Google Maps
63 "apdfllckaahabafndbhieahigkjlhalf", // Drive
64 extension_misc::kGoogleDocAppId,
65 extension_misc::kGoogleSheetsAppId,
66 extension_misc::kGoogleSlidesAppId,
67 "dlppkpafhbajpcmmoheippocdidnckmm", // Google+
68 "kbpgddbgniojgndnhlkjbkpknjhppkbk", // Google+ Hangouts
69 "hhaomjibdihmijegdhdafkllkbggdgoj", // Files
70 extension_misc::kGooglePlayMusicAppId,
71 "mmimngoggfoobjdlefbcabngfnmieonb", // Play Books
72 "fppdphmgcddhjeddoeghpjefkdlccljb", // Play Movies
73 "fobcpibfeplaikcclojfdhfdmbbeofai", // Games
74 "joodangkbfjnajiiifokapkpmhfnpleo", // Calculator
75 "hfhhnacclhffhdffklopdkcgdhifgngh", // Camera
76 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
79 for (size_t i = 0; i < arraysize(kDefaultAppOrder); ++i)
80 app_ids->push_back(std::string(kDefaultAppOrder[i]));
83 } // namespace
85 ExternalLoader::ExternalLoader(bool async)
86 : loaded_(true /* manual_rest */, false /* initially_signaled */) {
87 DCHECK(!loader_instance);
88 loader_instance = this;
90 if (async) {
91 content::BrowserThread::PostBlockingPoolTask(FROM_HERE,
92 base::Bind(&ExternalLoader::Load, base::Unretained(this)));
93 } else {
94 Load();
98 ExternalLoader::~ExternalLoader() {
99 DCHECK(loaded_.IsSignaled());
100 DCHECK_EQ(loader_instance, this);
101 loader_instance = NULL;
104 const std::vector<std::string>& ExternalLoader::GetAppIds() {
105 if (!loaded_.IsSignaled())
106 LOG(ERROR) << "GetAppIds() called before loaded.";
107 return app_ids_;
110 void ExternalLoader::Load() {
111 base::FilePath ordinals_file;
112 CHECK(PathService::Get(chromeos::FILE_DEFAULT_APP_ORDER, &ordinals_file));
114 scoped_ptr<base::ListValue> ordinals_value(
115 ReadExternalOrdinalFile(ordinals_file));
116 if (ordinals_value) {
117 for (size_t i = 0; i < ordinals_value->GetSize(); ++i) {
118 std::string app_id;
119 CHECK(ordinals_value->GetString(i, &app_id));
120 app_ids_.push_back(app_id);
122 } else {
123 GetDefault(&app_ids_);
126 loaded_.Signal();
129 void Get(std::vector<std::string>* app_ids) {
130 // |loader_instance| could be NULL for test.
131 if (!loader_instance) {
132 GetDefault(app_ids);
133 return;
136 *app_ids = loader_instance->GetAppIds();
139 } // namespace default_app_order
140 } // namespace chromeos