File: component_toolbar_actions_factory.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (96 lines) | stat: -rw-r--r-- 3,401 bytes parent folder | download
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
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2014 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/ui/toolbar/component_toolbar_actions_factory.h"

#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "chrome/browser/extensions/component_migration_helper.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
#include "extensions/common/feature_switch.h"

#if defined(ENABLE_MEDIA_ROUTER)
#include "chrome/browser/ui/toolbar/media_router_action.h"
#endif

namespace {

ComponentToolbarActionsFactory* testing_factory_ = nullptr;

base::LazyInstance<ComponentToolbarActionsFactory> lazy_factory =
    LAZY_INSTANCE_INITIALIZER;

const char kCastExtensionId[] = "boadgeojelhgndaghljhdicfkmllpafd";
const char kCastBetaExtensionId[] = "dliochdbjfkdbacpmhlcpmleaejidimm";

}  // namespace

// static
const char ComponentToolbarActionsFactory::kMediaRouterActionId[] =
    "media_router_action";

ComponentToolbarActionsFactory::ComponentToolbarActionsFactory() {}
ComponentToolbarActionsFactory::~ComponentToolbarActionsFactory() {}

// static
ComponentToolbarActionsFactory* ComponentToolbarActionsFactory::GetInstance() {
  return testing_factory_ ? testing_factory_ : &lazy_factory.Get();
}

std::set<std::string> ComponentToolbarActionsFactory::GetInitialComponentIds(
    Profile* profile) {
  std::set<std::string> component_ids;
  return component_ids;
}

std::unique_ptr<ToolbarActionViewController>
ComponentToolbarActionsFactory::GetComponentToolbarActionForId(
    const std::string& id,
    Browser* browser,
    ToolbarActionsBar* bar) {
  // This is currently behind the extension-action-redesign flag, as it is
  // designed for the new toolbar.
  DCHECK(extensions::FeatureSwitch::extension_action_redesign()->IsEnabled());

  // Add component toolbar actions here.
  // This current design means that the ComponentToolbarActionsFactory is aware
  // of all actions. Since we should *not* have an excessive amount of these
  // (since each will have an action in the toolbar or overflow menu), this
  // should be okay. If this changes, we should rethink this design to have,
  // e.g., RegisterChromeAction().
#if defined(ENABLE_MEDIA_ROUTER)
  if (id == kMediaRouterActionId)
    return std::unique_ptr<ToolbarActionViewController>(
        new MediaRouterAction(browser, bar));
#endif  // defined(ENABLE_MEDIA_ROUTER)

  NOTREACHED();
  return std::unique_ptr<ToolbarActionViewController>();
}

// static
void ComponentToolbarActionsFactory::SetTestingFactory(
    ComponentToolbarActionsFactory* factory) {
  testing_factory_ = factory;
}

void ComponentToolbarActionsFactory::RegisterComponentMigrations(
    extensions::ComponentMigrationHelper* helper) const {
  helper->Register(kMediaRouterActionId, kCastExtensionId);
  helper->Register(kMediaRouterActionId, kCastBetaExtensionId);
}

void ComponentToolbarActionsFactory::HandleComponentMigrations(
    extensions::ComponentMigrationHelper* helper,
    Profile* profile) const {
  if (media_router::MediaRouterEnabled(profile)) {
    helper->OnFeatureEnabled(kMediaRouterActionId);
  } else {
    helper->OnFeatureDisabled(kMediaRouterActionId);
  }
}