Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: chrome/browser/extensions/declarative_user_script_master.cc

Issue 420543002: Declarative content scripts: Browser-side: per-extension shared memory regions (lazily loaded) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor relationship between UserScriptMaster and its subclasses Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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.
4
5 #include "chrome/browser/extensions/declarative_user_script_master.h"
6
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/extension_util.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/extensions/api/i18n/default_locale_handler.h"
11 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/render_process_host.h"
13 #include "extensions/browser/content_verifier.h"
14 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/extension_system.h"
16
17 namespace extensions {
18
19 DeclarativeUserScriptMaster::DeclarativeUserScriptMaster(
20 Profile* profile,
21 const ExtensionId& extension_id)
22 : UserScriptMaster(profile, extension_id),
23 user_scripts_(new UserScriptList()) {
24 owner_extension_as_set_.insert(extension_id);
25 const Extension* extension =
26 ExtensionRegistry::Get(this->profile())
27 ->GetExtensionById(owner_extension_id(), ExtensionRegistry::ENABLED);
28 DCHECK(extension);
29 extensions_info_[owner_extension_id()] =
30 ExtensionSet::ExtensionPathAndDefaultLocale(
31 extension->path(), LocaleInfo::GetDefaultLocale(extension));
32 }
33
34 DeclarativeUserScriptMaster::~DeclarativeUserScriptMaster() {
35 }
36
37 void DeclarativeUserScriptMaster::AddScript(const UserScript& script) {
38 scripts_to_add_.insert(script);
39 AttemptLoad();
40 }
41
42 void DeclarativeUserScriptMaster::RemoveScript(const UserScript& script) {
43 if (scripts_to_add_.count(script) != 0)
44 scripts_to_add_.erase(script);
45 else
46 scripts_to_remove_.insert(script);
47 AttemptLoad();
Devlin 2014/07/31 20:32:23 Seems to me there's no reason to attempt the load
48 }
49
50 void DeclarativeUserScriptMaster::ClearScripts() {
51 clear_scripts_ = true;
52 scripts_to_add_.clear();
53 scripts_to_remove_.clear();
54 AttemptLoad();
55 }
56
57 void DeclarativeUserScriptMaster::StartLoad() {
58 if (clear_scripts_) {
59 user_scripts_->clear();
60 }
61 bool incognito_enabled =
62 util::IsIncognitoEnabled(owner_extension_id(), profile());
63 std::set<UserScript> new_user_scripts;
64 new_user_scripts.insert(user_scripts_->begin(), user_scripts_->end());
Devlin 2014/07/31 20:32:23 If we wanted to be cool, we would do: user_scripts
65 for (std::set<UserScript>::iterator it = scripts_to_remove_.begin();
66 it != scripts_to_remove_.end();
67 ++it) {
68 new_user_scripts.erase(*it);
69 }
70 for (std::set<UserScript>::const_iterator it = scripts_to_add_.begin();
71 it != scripts_to_add_.end();
72 ++it) {
73 UserScript script = *it;
74 script.set_incognito_enabled(incognito_enabled);
75 new_user_scripts.insert(script);
76 }
77 user_scripts_->assign(new_user_scripts.begin(), new_user_scripts.end());
78
79 LoadScripts(user_scripts_.Pass(), extensions_info_);
80
81 user_scripts_.reset(NULL);
82 scripts_to_add_.clear();
83 scripts_to_remove_.clear();
84 clear_scripts_ = false;
85 }
86
87 void DeclarativeUserScriptMaster::AcquireUserScripts(
88 scoped_ptr<UserScriptList> scripts) {
89 user_scripts_.reset(scripts.release());
90 }
91
92 ExtensionsInfo DeclarativeUserScriptMaster::GetExtensionsInfo() {
93 return extensions_info_;
94 }
95
96 std::set<ExtensionId> DeclarativeUserScriptMaster::GetAddedExtensions() {
97 // If loading from the file thread has been triggered, then reload scripts
98 // for the one extension that we manage.
99 return owner_extension_as_set_;
100 }
101
102 std::set<ExtensionId> DeclarativeUserScriptMaster::GetAllManagedExtensions() {
103 return owner_extension_as_set_;
104 }
105
106 std::set<ExtensionId> DeclarativeUserScriptMaster::GetChangedExtensions() {
107 // In any context where we need to know which extensions have changed, assume
108 // that the extension we manage may have changed.
109 return owner_extension_as_set_;
110 }
111
112 void DeclarativeUserScriptMaster::ResetChangedExtensions() {
113 // No extra bookkeeping for tracking changed extensions.
114 }
115
116 void DeclarativeUserScriptMaster::AttemptLoad() {
117 if (is_loading())
118 MaybeSignalPendingLoad();
119 else
120 StartLoad();
121 }
122
123 void DeclarativeUserScriptMaster::MaybeSignalPendingLoad() {
124 if (clear_scripts_ || scripts_to_add_.size() > 0 ||
125 scripts_to_remove_.size() > 0)
126 SignalPendingLoad();
127 }
128
129 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698