1 // Copyright 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/plugins/plugins_resource_service.h"
8 #include "base/command_line.h"
9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/plugins/plugin_finder.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h"
15 #include "components/safe_json/safe_json_parser.h"
20 // Delay on first fetch so we don't interfere with startup.
21 const int kStartResourceFetchDelayMs
= 60 * 1000;
23 // Delay between calls to update the cache 1 day and 2 minutes in testing mode.
24 const int kCacheUpdateDelayMs
= 24 * 60 * 60 * 1000;
26 const char kPluginsServerUrl
[] =
27 "https://www.gstatic.com/chrome/config/plugins_2/";
29 GURL
GetPluginsServerURL() {
32 filename
= "plugins_win.json";
33 #elif defined(OS_LINUX)
34 filename
= "plugins_linux.json";
35 #elif defined(OS_MACOSX)
36 filename
= "plugins_mac.json";
38 #error Unknown platform
41 return GURL(kPluginsServerUrl
+ filename
);
46 PluginsResourceService::PluginsResourceService(PrefService
* local_state
)
47 : web_resource::WebResourceService(
49 GetPluginsServerURL(),
51 prefs::kPluginsResourceCacheUpdate
,
52 kStartResourceFetchDelayMs
,
54 g_browser_process
->system_request_context(),
55 switches::kDisableBackgroundNetworking
,
56 base::Bind(safe_json::SafeJsonParser::Parse
)) {}
58 void PluginsResourceService::Init() {
59 const base::DictionaryValue
* metadata
=
60 prefs_
->GetDictionary(prefs::kPluginsMetadata
);
61 PluginFinder::GetInstance()->ReinitializePlugins(metadata
);
65 PluginsResourceService::~PluginsResourceService() {
69 void PluginsResourceService::RegisterPrefs(PrefRegistrySimple
* registry
) {
70 registry
->RegisterDictionaryPref(prefs::kPluginsMetadata
,
71 new base::DictionaryValue());
72 registry
->RegisterStringPref(prefs::kPluginsResourceCacheUpdate
, "0");
75 void PluginsResourceService::Unpack(const base::DictionaryValue
& parsed_json
) {
76 prefs_
->Set(prefs::kPluginsMetadata
, parsed_json
);
77 PluginFinder::GetInstance()->ReinitializePlugins(&parsed_json
);