Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / plugins / plugins_resource_service.cc
blob4dee5438dc0419a57214a7683ea70448aaf35b5d
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"
7 #include "base/bind.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"
16 #include "url/gurl.h"
18 namespace {
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() {
30 std::string filename;
31 #if defined(OS_WIN)
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";
37 #else
38 #error Unknown platform
39 #endif
41 return GURL(kPluginsServerUrl + filename);
44 } // namespace
46 PluginsResourceService::PluginsResourceService(PrefService* local_state)
47 : web_resource::WebResourceService(
48 local_state,
49 GetPluginsServerURL(),
50 std::string(),
51 prefs::kPluginsResourceCacheUpdate,
52 kStartResourceFetchDelayMs,
53 kCacheUpdateDelayMs,
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);
62 StartAfterDelay();
65 PluginsResourceService::~PluginsResourceService() {
68 // static
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);