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

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

Issue 214343002: Refactor SharedWorkerHost and SharedWorkerInstance. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 8 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_instance.h" 5 #include "content/browser/shared_worker/shared_worker_instance.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/worker_host/worker_document_set.h"
9 8
10 namespace content { 9 namespace content {
11 10
12 SharedWorkerInstance::SharedWorkerInstance( 11 SharedWorkerInstance::SharedWorkerInstance(
13 const GURL& url, 12 const GURL& url,
14 const base::string16& name, 13 const base::string16& name,
15 const base::string16& content_security_policy, 14 const base::string16& content_security_policy,
16 blink::WebContentSecurityPolicyType security_policy_type, 15 blink::WebContentSecurityPolicyType security_policy_type,
17 ResourceContext* resource_context, 16 ResourceContext* resource_context,
18 const WorkerStoragePartition& partition) 17 const WorkerStoragePartition& partition)
19 : url_(url), 18 : url_(url),
20 closed_(false),
21 name_(name), 19 name_(name),
22 content_security_policy_(content_security_policy), 20 content_security_policy_(content_security_policy),
23 security_policy_type_(security_policy_type), 21 security_policy_type_(security_policy_type),
24 worker_document_set_(new WorkerDocumentSet()),
25 resource_context_(resource_context), 22 resource_context_(resource_context),
26 partition_(partition), 23 partition_(partition) {
27 load_failed_(false) {
28 DCHECK(resource_context_); 24 DCHECK(resource_context_);
29 } 25 }
30 26
31 SharedWorkerInstance::~SharedWorkerInstance() { 27 SharedWorkerInstance::~SharedWorkerInstance() {
32 } 28 }
33 29
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 }
44 }
45
46 bool SharedWorkerInstance::Matches(const GURL& match_url, 30 bool SharedWorkerInstance::Matches(const GURL& match_url,
47 const base::string16& match_name, 31 const base::string16& match_name,
48 const WorkerStoragePartition& partition, 32 const WorkerStoragePartition& partition,
49 ResourceContext* resource_context) const { 33 ResourceContext* resource_context) const {
50 // Only match open shared workers.
51 if (closed_)
52 return false;
53
54 // ResourceContext equivalence is being used as a proxy to ensure we only 34 // ResourceContext equivalence is being used as a proxy to ensure we only
55 // matched shared workers within the same BrowserContext. 35 // matched shared workers within the same BrowserContext.
56 if (resource_context_ != resource_context) 36 if (resource_context_ != resource_context)
57 return false; 37 return false;
58 38
59 // We must be in the same storage partition otherwise sharing will violate 39 // We must be in the same storage partition otherwise sharing will violate
60 // isolation. 40 // isolation.
61 if (!partition_.Equals(partition)) 41 if (!partition_.Equals(partition))
62 return false; 42 return false;
63 43
64 if (url_.GetOrigin() != match_url.GetOrigin()) 44 if (url_.GetOrigin() != match_url.GetOrigin())
65 return false; 45 return false;
66 46
67 if (name_.empty() && match_name.empty()) 47 if (name_.empty() && match_name.empty())
68 return url_ == match_url; 48 return url_ == match_url;
69 49
70 return name_ == match_name; 50 return name_ == match_name;
71 } 51 }
72 52
73 void SharedWorkerInstance::AddFilter(SharedWorkerMessageFilter* filter,
74 int route_id) {
75 CHECK(filter);
76 if (!HasFilter(filter, route_id)) {
77 FilterInfo info(filter, route_id);
78 filters_.push_back(info);
79 }
80 }
81
82 void SharedWorkerInstance::RemoveFilters(SharedWorkerMessageFilter* filter) {
83 for (FilterList::iterator i = filters_.begin(); i != filters_.end();) {
84 if (i->filter() == filter)
85 i = filters_.erase(i);
86 else
87 ++i;
88 }
89 }
90
91 bool SharedWorkerInstance::HasFilter(SharedWorkerMessageFilter* filter,
92 int route_id) const {
93 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end();
94 ++i) {
95 if (i->filter() == filter && i->route_id() == route_id)
96 return true;
97 }
98 return false;
99 }
100
101 } // namespace content 53 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/shared_worker/shared_worker_instance.h ('k') | content/browser/shared_worker/shared_worker_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698