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

Side by Side Diff: content/browser/service_worker/embedded_worker_instance.cc

Issue 127573002: Add basic browser test for EmbeddedWorker/ServiceWorker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: copyright fix Created 6 years, 11 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/service_worker/embedded_worker_instance.h" 5 #include "content/browser/service_worker/embedded_worker_instance.h"
6 6
7 #include "content/browser/service_worker/embedded_worker_registry.h" 7 #include "content/browser/service_worker/embedded_worker_registry.h"
8 #include "content/common/service_worker/embedded_worker_messages.h" 8 #include "content/common/service_worker/embedded_worker_messages.h"
9 #include "url/gurl.h" 9 #include "url/gurl.h"
10 10
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 thread_id_(-1) { 78 thread_id_(-1) {
79 } 79 }
80 80
81 void EmbeddedWorkerInstance::OnStarted(int thread_id) { 81 void EmbeddedWorkerInstance::OnStarted(int thread_id) {
82 // Stop is requested before OnStarted is sent back from the worker. 82 // Stop is requested before OnStarted is sent back from the worker.
83 if (status_ == STOPPING) 83 if (status_ == STOPPING)
84 return; 84 return;
85 DCHECK(status_ == STARTING); 85 DCHECK(status_ == STARTING);
86 status_ = RUNNING; 86 status_ = RUNNING;
87 thread_id_ = thread_id; 87 thread_id_ = thread_id;
88 FOR_EACH_OBSERVER(Observer, observer_list_, OnStarted());
88 } 89 }
89 90
90 void EmbeddedWorkerInstance::OnStopped() { 91 void EmbeddedWorkerInstance::OnStopped() {
91 status_ = STOPPED; 92 status_ = STOPPED;
92 process_id_ = -1; 93 process_id_ = -1;
93 thread_id_ = -1; 94 thread_id_ = -1;
95 FOR_EACH_OBSERVER(Observer, observer_list_, OnStopped());
96 }
97
98 void EmbeddedWorkerInstance::AddObserver(Observer* observer) {
99 observer_list_.AddObserver(observer);
100 }
101
102 void EmbeddedWorkerInstance::RemoveObserver(Observer* observer) {
103 observer_list_.RemoveObserver(observer);
94 } 104 }
95 105
96 bool EmbeddedWorkerInstance::ChooseProcess() { 106 bool EmbeddedWorkerInstance::ChooseProcess() {
97 DCHECK_EQ(-1, process_id_); 107 DCHECK_EQ(-1, process_id_);
98 // Naive implementation; chooses a process which has the biggest number of 108 // Naive implementation; chooses a process which has the biggest number of
99 // associated providers (so that hopefully likely live longer). 109 // associated providers (so that hopefully likely live longer).
100 ProcessRefMap::iterator max_ref_iter = process_refs_.end(); 110 ProcessRefMap::iterator max_ref_iter = process_refs_.end();
101 for (ProcessRefMap::iterator iter = process_refs_.begin(); 111 for (ProcessRefMap::iterator iter = process_refs_.begin();
102 iter != process_refs_.end(); ++iter) { 112 iter != process_refs_.end(); ++iter) {
103 if (max_ref_iter == process_refs_.end() || 113 if (max_ref_iter == process_refs_.end() ||
104 max_ref_iter->second < iter->second) 114 max_ref_iter->second < iter->second)
105 max_ref_iter = iter; 115 max_ref_iter = iter;
106 } 116 }
107 if (max_ref_iter == process_refs_.end()) 117 if (max_ref_iter == process_refs_.end())
108 return false; 118 return false;
109 process_id_ = max_ref_iter->first; 119 process_id_ = max_ref_iter->first;
110 return true; 120 return true;
111 } 121 }
112 122
113 } // namespace content 123 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698