Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / shared_worker / shared_worker_instance.cc
blobea8e02db7053dafa55d7c5a44a155e110b40b0cf
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.
5 #include "content/browser/shared_worker/shared_worker_instance.h"
7 #include "base/logging.h"
9 namespace content {
11 SharedWorkerInstance::SharedWorkerInstance(
12 const GURL& url,
13 const base::string16& name,
14 const base::string16& content_security_policy,
15 blink::WebContentSecurityPolicyType security_policy_type,
16 ResourceContext* resource_context,
17 const WorkerStoragePartitionId& partition_id)
18 : url_(url),
19 name_(name),
20 content_security_policy_(content_security_policy),
21 security_policy_type_(security_policy_type),
22 resource_context_(resource_context),
23 partition_id_(partition_id) {
24 DCHECK(resource_context_);
27 SharedWorkerInstance::SharedWorkerInstance(const SharedWorkerInstance& other)
28 : url_(other.url_),
29 name_(other.name_),
30 content_security_policy_(other.content_security_policy_),
31 security_policy_type_(other.security_policy_type_),
32 resource_context_(other.resource_context_),
33 partition_id_(other.partition_id_) {
36 SharedWorkerInstance::~SharedWorkerInstance() {}
38 bool SharedWorkerInstance::Matches(const GURL& match_url,
39 const base::string16& match_name,
40 const WorkerStoragePartitionId& partition_id,
41 ResourceContext* resource_context) const {
42 // ResourceContext equivalence is being used as a proxy to ensure we only
43 // matched shared workers within the same BrowserContext.
44 if (resource_context_ != resource_context)
45 return false;
47 // We must be in the same storage partition otherwise sharing will violate
48 // isolation.
49 if (!partition_id_.Equals(partition_id))
50 return false;
52 if (url_.GetOrigin() != match_url.GetOrigin())
53 return false;
55 if (name_.empty() && match_name.empty())
56 return url_ == match_url;
58 return name_ == match_name;
61 bool SharedWorkerInstance::Matches(const SharedWorkerInstance& other) const {
62 return Matches(other.url(),
63 other.name(),
64 other.partition_id(),
65 other.resource_context());
68 } // namespace content