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

Side by Side Diff: content/browser/shared_worker/shared_worker_instance.cc

Issue 177043003: Implement SharedWorkerServiceImpl::CreateWorker and SharedWorkerInstance and SharedWorkerHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/shared_worker/shared_worker_service_impl.h" 5 #include "content/browser/shared_worker/shared_worker_instance.h"
6 6
7 #include "content/browser/shared_worker/shared_worker_message_filter.h" 7 #include "base/logging.h"
8 #include "content/common/worker_messages.h" 8 #include "content/browser/worker_host/worker_document_set.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/worker_service_observer.h"
11 9
12 namespace content { 10 namespace content {
13 11
14 SharedWorkerServiceImpl* SharedWorkerServiceImpl::GetInstance() { 12 SharedWorkerInstance::SharedWorkerInstance(
15 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 13 const GURL& url,
16 return Singleton<SharedWorkerServiceImpl>::get(); 14 const base::string16& name,
15 const base::string16& content_security_policy,
16 blink::WebContentSecurityPolicyType security_policy_type,
17 ResourceContext* resource_context,
18 const WorkerStoragePartition& partition)
19 : url_(url),
20 closed_(false),
21 name_(name),
22 content_security_policy_(content_security_policy),
23 security_policy_type_(security_policy_type),
24 worker_document_set_(new WorkerDocumentSet()),
25 resource_context_(resource_context),
26 partition_(partition),
27 load_failed_(false) {
28 DCHECK(resource_context_);
17 } 29 }
18 30
19 SharedWorkerServiceImpl::SharedWorkerServiceImpl() { 31 SharedWorkerInstance::~SharedWorkerInstance() {
20 } 32 }
21 33
22 SharedWorkerServiceImpl::~SharedWorkerServiceImpl() { 34 void SharedWorkerInstance::SetMessagePortID(
35 SharedWorkerMessageFilter* filter,
36 int route_id,
37 int message_port_id) {
38 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) {
39 if (i->filter() == filter && i->route_id() == route_id) {
40 i->set_message_port_id(message_port_id);
41 return;
42 }
43 }
23 } 44 }
24 45
25 bool SharedWorkerServiceImpl::TerminateWorker(int process_id, int route_id) { 46 // Compares an instance based on the algorithm in the WebWorkers spec - an
26 // TODO(horo): implement this. 47 // instance matches if the origins of the URLs match, and:
48 // a) the names are non-empty and equal
49 // -or-
50 // b) the names are both empty, and the urls are equal
kinuko 2014/02/26 08:51:17 This comments can be probably moved to .h
horo 2014/02/26 10:36:19 Done.
51 bool SharedWorkerInstance::Matches(const GURL& match_url,
52 const base::string16& match_name,
53 const WorkerStoragePartition& partition,
54 ResourceContext* resource_context) const {
55 // Only match open shared workers.
56 if (closed_)
57 return false;
58
59 // ResourceContext equivalence is being used as a proxy to ensure we only
60 // matched shared workers within the same BrowserContext.
61 if (resource_context_ != resource_context)
62 return false;
63
64 // We must be in the same storage partition otherwise sharing will violate
65 // isolation.
66 if (!partition_.Equals(partition))
67 return false;
68
69 if (url_.GetOrigin() != match_url.GetOrigin())
70 return false;
71
72 if (name_.empty() && match_name.empty())
73 return url_ == match_url;
74
75 return name_ == match_name;
76 }
77
78 void SharedWorkerInstance::AddFilter(SharedWorkerMessageFilter* filter,
79 int route_id) {
80 CHECK(filter);
81 if (!HasFilter(filter, route_id)) {
82 FilterInfo info(filter, route_id);
83 filters_.push_back(info);
84 }
85 }
86
87 void SharedWorkerInstance::RemoveFilters(SharedWorkerMessageFilter* filter) {
88 for (FilterList::iterator i = filters_.begin(); i != filters_.end();) {
89 if (i->filter() == filter)
90 i = filters_.erase(i);
91 else
92 ++i;
93 }
94 }
95
96 bool SharedWorkerInstance::HasFilter(SharedWorkerMessageFilter* filter,
97 int route_id) const {
98 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end();
99 ++i) {
100 if (i->filter() == filter && i->route_id() == route_id)
101 return true;
102 }
27 return false; 103 return false;
28 } 104 }
29 105
30 std::vector<WorkerService::WorkerInfo> SharedWorkerServiceImpl::GetWorkers() {
31 // TODO(horo): implement this.
32 std::vector<WorkerService::WorkerInfo> results;
33 return results;
34 }
35
36 void SharedWorkerServiceImpl::AddObserver(WorkerServiceObserver* observer) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
38 observers_.AddObserver(observer);
39 }
40
41 void SharedWorkerServiceImpl::RemoveObserver(WorkerServiceObserver* observer) {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
43 observers_.RemoveObserver(observer);
44 }
45
46 void SharedWorkerServiceImpl::CreateWorker(
47 const ViewHostMsg_CreateWorker_Params& params,
48 int route_id,
49 SharedWorkerMessageFilter* filter,
50 ResourceContext* resource_context,
51 const WorkerStoragePartition& partition,
52 bool* url_mismatch) {
53 // TODO(horo): implement this.
54 NOTIMPLEMENTED();
55 }
56
57 void SharedWorkerServiceImpl::ForwardToWorker(
58 const IPC::Message& message,
59 SharedWorkerMessageFilter* filter) {
60 // TODO(horo): implement this.
61 NOTIMPLEMENTED();
62 }
63
64 void SharedWorkerServiceImpl::DocumentDetached(
65 unsigned long long document_id,
66 SharedWorkerMessageFilter* filter) {
67 // TODO(horo): implement this.
68 NOTIMPLEMENTED();
69 }
70
71 void SharedWorkerServiceImpl::WorkerContextClosed(
72 int worker_route_id,
73 SharedWorkerMessageFilter* filter) {
74 // TODO(horo): implement this.
75 NOTIMPLEMENTED();
76 }
77
78 void SharedWorkerServiceImpl::WorkerContextDestroyed(
79 int worker_route_id,
80 SharedWorkerMessageFilter* filter) {
81 // TODO(horo): implement this.
82 NOTIMPLEMENTED();
83 }
84
85 void SharedWorkerServiceImpl::WorkerScriptLoaded(
86 int worker_route_id,
87 SharedWorkerMessageFilter* filter) {
88 // TODO(horo): implement this.
89 NOTIMPLEMENTED();
90 }
91
92 void SharedWorkerServiceImpl::WorkerScriptLoadFailed(
93 int worker_route_id,
94 SharedWorkerMessageFilter* filter) {
95 // TODO(horo): implement this.
96 NOTIMPLEMENTED();
97 }
98
99 void SharedWorkerServiceImpl::WorkerConnected(
100 int message_port_id,
101 int worker_route_id,
102 SharedWorkerMessageFilter* filter) {
103 // TODO(horo): implement this.
104 NOTIMPLEMENTED();
105 }
106
107 void SharedWorkerServiceImpl::AllowDatabase(
108 int worker_route_id,
109 const GURL& url,
110 const base::string16& name,
111 const base::string16& display_name,
112 unsigned long estimated_size,
113 bool* result,
114 SharedWorkerMessageFilter* filter) {
115 // TODO(horo): implement this.
116 NOTIMPLEMENTED();
117 }
118
119 void SharedWorkerServiceImpl::AllowFileSystem(
120 int worker_route_id,
121 const GURL& url,
122 bool* result,
123 SharedWorkerMessageFilter* filter) {
124 // TODO(horo): implement this.
125 NOTIMPLEMENTED();
126 }
127
128 void SharedWorkerServiceImpl::AllowIndexedDB(
129 int worker_route_id,
130 const GURL& url,
131 const base::string16& name,
132 bool* result,
133 SharedWorkerMessageFilter* filter) {
134 // TODO(horo): implement this.
135 NOTIMPLEMENTED();
136 }
137
138 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing(
139 SharedWorkerMessageFilter* filter) {
140 // TODO(horo): implement this.
141 NOTIMPLEMENTED();
142 }
143
144 } // namespace content 106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698