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

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

Issue 6961027: Change event routers from singletons to being owned by the ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: all is built on sand Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_processes_api.h" 5 #include "chrome/browser/extensions/extension_processes_api.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 24 matching lines...) Expand all
35 DictionaryValue* result = new DictionaryValue(); 35 DictionaryValue* result = new DictionaryValue();
36 result->SetInteger(keys::kIdKey, process_id); 36 result->SetInteger(keys::kIdKey, process_id);
37 result->SetString(keys::kTypeKey, type); 37 result->SetString(keys::kTypeKey, type);
38 result->SetDouble(keys::kCpuKey, cpu); 38 result->SetDouble(keys::kCpuKey, cpu);
39 result->SetDouble(keys::kNetworkKey, static_cast<double>(net)); 39 result->SetDouble(keys::kNetworkKey, static_cast<double>(net));
40 result->SetDouble(keys::kPrivateMemoryKey, static_cast<double>(pr_mem)); 40 result->SetDouble(keys::kPrivateMemoryKey, static_cast<double>(pr_mem));
41 result->SetDouble(keys::kSharedMemoryKey, static_cast<double>(sh_mem)); 41 result->SetDouble(keys::kSharedMemoryKey, static_cast<double>(sh_mem));
42 return result; 42 return result;
43 } 43 }
44 44
45 ExtensionProcessesEventRouter* ExtensionProcessesEventRouter::GetInstance() { 45 ExtensionProcessesEventRouter::ExtensionProcessesEventRouter(Profile* profile)
46 return Singleton<ExtensionProcessesEventRouter>::get(); 46 : profile_(profile) {
47 }
48
49 ExtensionProcessesEventRouter::ExtensionProcessesEventRouter() {
50 model_ = TaskManager::GetInstance()->model();
51 model_->AddObserver(this);
52 } 47 }
53 48
54 ExtensionProcessesEventRouter::~ExtensionProcessesEventRouter() { 49 ExtensionProcessesEventRouter::~ExtensionProcessesEventRouter() {
55 model_->RemoveObserver(this); 50 model_->RemoveObserver(this);
56 } 51 }
57 52
58 void ExtensionProcessesEventRouter::ObserveProfile(Profile* profile) { 53 void ExtensionProcessesEventRouter::Init() {
59 profiles_.insert(profile); 54 model_ = TaskManager::GetInstance()->model();
55 model_->AddObserver(this);
60 } 56 }
61 57
62 void ExtensionProcessesEventRouter::ListenerAdded() { 58 void ExtensionProcessesEventRouter::ListenerAdded() {
63 model_->StartUpdating(); 59 model_->StartUpdating();
64 } 60 }
65 61
66 void ExtensionProcessesEventRouter::ListenerRemoved() { 62 void ExtensionProcessesEventRouter::ListenerRemoved() {
67 model_->StopUpdating(); 63 model_->StopUpdating();
68 } 64 }
69 65
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // Store each process indexed by the string version of its id 127 // Store each process indexed by the string version of its id
132 processes->Set(base::IntToString(id), 128 processes->Set(base::IntToString(id),
133 CreateProcessValue(id, type, cpu, net, pr_mem, sh_mem)); 129 CreateProcessValue(id, type, cpu, net, pr_mem, sh_mem));
134 } 130 }
135 } 131 }
136 args.Append(processes); 132 args.Append(processes);
137 133
138 std::string json_args; 134 std::string json_args;
139 base::JSONWriter::Write(&args, false, &json_args); 135 base::JSONWriter::Write(&args, false, &json_args);
140 136
141 // Notify each profile that is interested. 137 // Notify the profile.
142 for (ProfileSet::iterator it = profiles_.begin(); 138 DispatchEvent(profile_, keys::kOnUpdated, json_args);
143 it != profiles_.end(); it++) {
144 Profile* profile = *it;
145 DispatchEvent(profile, keys::kOnUpdated, json_args);
146 }
147 } 139 }
148 } 140 }
149 141
150 void ExtensionProcessesEventRouter::DispatchEvent(Profile* profile, 142 void ExtensionProcessesEventRouter::DispatchEvent(Profile* profile,
151 const char* event_name, 143 const char* event_name,
152 const std::string& json_args) { 144 const std::string& json_args) {
153 if (profile && profile->GetExtensionEventRouter()) { 145 if (profile && profile->GetExtensionEventRouter()) {
154 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 146 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
155 event_name, json_args, NULL, GURL()); 147 event_name, json_args, NULL, GURL());
156 } 148 }
(...skipping 12 matching lines...) Expand all
169 base::IntToString(tab_id)); 161 base::IntToString(tab_id));
170 return false; 162 return false;
171 } 163 }
172 164
173 // Return the process ID of the tab as an integer. 165 // Return the process ID of the tab as an integer.
174 int id = base::GetProcId(contents->tab_contents()-> 166 int id = base::GetProcId(contents->tab_contents()->
175 GetRenderProcessHost()->GetHandle()); 167 GetRenderProcessHost()->GetHandle());
176 result_.reset(Value::CreateIntegerValue(id)); 168 result_.reset(Value::CreateIntegerValue(id));
177 return true; 169 return true;
178 } 170 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_processes_api.h ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698