summaryrefslogtreecommitdiffstats
path: root/chrome/browser/plugins/plugins_resource_service.cc
blob: 348ad13c324d0633e46d5c0f33258348899a68c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/plugins/plugins_resource_service.h"

#include "base/command_line.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/plugins/plugin_finder.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "googleurl/src/gurl.h"

namespace {

// Delay on first fetch so we don't interfere with startup.
const int kStartResourceFetchDelayMs = 60 * 1000;

// Delay between calls to update the cache 1 day and 2 minutes in testing mode.
const int kCacheUpdateDelayMs = 24 * 60 * 60 * 1000;
const int kTestCacheUpdateDelayMs = 2 * 60 * 1000;

const char kPluginsServerUrl[] =
    "https://www.gstatic.com/chrome/config/plugins_2/";

bool IsTest() {
  return CommandLine::ForCurrentProcess()->HasSwitch(
      switches::kPluginsMetadataServerURL);
}

GURL GetPluginsServerURL() {
  std::string filename;
#if defined(OS_WIN)
  filename = "plugins_win.json";
#elif defined(OS_LINUX)
  filename = "plugins_linux.json";
#elif defined(OS_MACOSX)
  filename = "plugins_mac.json";
#else
#error Unknown platform
#endif

  std::string test_url =
      CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
          switches::kPluginsMetadataServerURL);
  return GURL(IsTest() ? test_url : kPluginsServerUrl + filename);
}

int GetCacheUpdateDelay() {
  return IsTest() ? kTestCacheUpdateDelayMs : kCacheUpdateDelayMs;
}

}  // namespace

PluginsResourceService::PluginsResourceService(PrefService* local_state)
    : WebResourceService(local_state,
                         GetPluginsServerURL(),
                         false,
                         prefs::kPluginsResourceCacheUpdate,
                         kStartResourceFetchDelayMs,
                         GetCacheUpdateDelay()) {
}

void PluginsResourceService::Init() {
  const base::DictionaryValue* metadata =
      prefs_->GetDictionary(prefs::kPluginsMetadata);
  PluginFinder::GetInstance()->ReinitializePlugins(metadata);
  StartAfterDelay();
}

PluginsResourceService::~PluginsResourceService() {
}

// static
void PluginsResourceService::RegisterPrefs(PrefRegistrySimple* registry) {
  registry->RegisterDictionaryPref(prefs::kPluginsMetadata,
                                   new base::DictionaryValue());
  registry->RegisterStringPref(prefs::kPluginsResourceCacheUpdate, "0");
}

void PluginsResourceService::Unpack(const DictionaryValue& parsed_json) {
  prefs_->Set(prefs::kPluginsMetadata, parsed_json);
  PluginFinder::GetInstance()->ReinitializePlugins(&parsed_json);
}