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

Side by Side Diff: extensions/common/consumer_id.cc

Issue 822453002: Introduce HostID and de-couple Extensions from "script injection System" [browser side] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another round of comments of Devlin@. Created 5 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
OLDNEW
(Empty)
1 // Copyright 2015 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.
4
5 #include "extensions/common/consumer_id.h"
6
7 namespace {
Devlin 2015/01/21 23:25:20 nit: newline
Xi Han 2015/01/22 17:19:36 Done.
8 // Default instance ID of a consumer who owns statically defined user scripts.
9 const int kDefaultInstanceID = 0;
10
11 int current_instance_id_ = kDefaultInstanceID;
12
13 // Get next available instance ID.
14 int GetNextID() {
15 return ++current_instance_id_;
16 }
17
18 } // namespace
19
20 ConsumerID::ConsumerID() {
21 }
22
23 ConsumerID::ConsumerID(HostType host_type,
24 const std::string& host_id,
25 InstanceType instance_type,
26 int instance_id)
27 : host_type_(host_type),
28 host_id_(host_id),
29 instance_type_(instance_type),
30 instance_id_(instance_id) {
31 }
32
33 ConsumerID::ConsumerID(HostType host_type,
34 const std::string& host_id,
35 InstanceType instance_type,
36 bool is_declarative)
37 : host_type_(host_type), host_id_(host_id), instance_type_(instance_type) {
38 instance_id_ = is_declarative ? GetNextID() : kDefaultInstanceID;
39 }
40
41 bool ConsumerID::operator<(const ConsumerID& id) const {
42 if (host_type_ != id.host_type())
43 return host_type_ < id.host_type();
44 if (host_id_ != id.host_id())
45 return host_id_ < id.host_id();
46 if (instance_type_ != id.instance_type())
47 return instance_type_ < id.instance_type();
48 if (instance_id_ != id.instance_id())
49 return instance_id_ < id.instance_id();
50 return false;
51 }
52
53 void ConsumerID::operator=(const ConsumerID& id) {
54 host_type_ = id.host_type();
55 host_id_ = id.host_id();
56 instance_type_ = id.instance_type();
57 instance_id_ = id.instance_id();
58 }
59
60 ConsumerID::~ConsumerID() {
61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698