| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/extensions/process_map.h" | 5 #include "chrome/browser/extensions/process_map.h" |
| 6 | 6 |
| 7 namespace extensions { | 7 namespace extensions { |
| 8 | 8 |
| 9 // Item | 9 // Item |
| 10 ProcessMap::Item::Item() { | 10 struct ProcessMap::Item { |
| 11 } | 11 Item() { |
| 12 | |
| 13 ProcessMap::Item::Item(const ProcessMap::Item& other) | |
| 14 : extension_id(other.extension_id), process_id(other.process_id) { | |
| 15 } | |
| 16 | |
| 17 ProcessMap::Item::Item(const std::string& extension_id, int process_id) | |
| 18 : extension_id(extension_id), process_id(process_id) { | |
| 19 } | |
| 20 | |
| 21 ProcessMap::Item::~Item() { | |
| 22 } | |
| 23 | |
| 24 bool ProcessMap::Item::operator<(const ProcessMap::Item& other) const { | |
| 25 if (extension_id < other.extension_id) | |
| 26 return true; | |
| 27 | |
| 28 if (extension_id == other.extension_id && | |
| 29 process_id < other.process_id) { | |
| 30 return true; | |
| 31 } | 12 } |
| 32 | 13 |
| 33 return false; | 14 explicit Item(const ProcessMap::Item& other) |
| 34 } | 15 : extension_id(other.extension_id), |
| 16 process_id(other.process_id), |
| 17 site_instance_id(other.site_instance_id) { |
| 18 } |
| 19 |
| 20 Item(const std::string& extension_id, int process_id, |
| 21 int site_instance_id) |
| 22 : extension_id(extension_id), |
| 23 process_id(process_id), |
| 24 site_instance_id(site_instance_id) { |
| 25 } |
| 26 |
| 27 ~Item() { |
| 28 } |
| 29 |
| 30 bool operator<(const ProcessMap::Item& other) const { |
| 31 if (extension_id < other.extension_id) |
| 32 return true; |
| 33 |
| 34 if (extension_id == other.extension_id && |
| 35 process_id < other.process_id) { |
| 36 return true; |
| 37 } |
| 38 |
| 39 if (extension_id == other.extension_id && |
| 40 process_id == other.process_id && |
| 41 site_instance_id < other.site_instance_id) { |
| 42 return true; |
| 43 } |
| 44 |
| 45 return false; |
| 46 } |
| 47 |
| 48 std::string extension_id; |
| 49 int process_id; |
| 50 int site_instance_id; |
| 51 }; |
| 35 | 52 |
| 36 | 53 |
| 37 // ProcessMap | 54 // ProcessMap |
| 38 ProcessMap::ProcessMap() { | 55 ProcessMap::ProcessMap() { |
| 39 } | 56 } |
| 40 | 57 |
| 41 ProcessMap::~ProcessMap() { | 58 ProcessMap::~ProcessMap() { |
| 42 } | 59 } |
| 43 | 60 |
| 44 bool ProcessMap::Insert(const std::string& extension_id, int process_id) { | 61 bool ProcessMap::Insert(const std::string& extension_id, int process_id, |
| 45 return items_.insert(Item(extension_id, process_id)).second; | 62 int site_instance_id) { |
| 63 return items_.insert(Item(extension_id, process_id, site_instance_id)).second; |
| 46 } | 64 } |
| 47 | 65 |
| 48 bool ProcessMap::Remove(const std::string& extension_id, int process_id) { | 66 bool ProcessMap::Remove(const std::string& extension_id, int process_id, |
| 49 return items_.erase(Item(extension_id, process_id)) > 0; | 67 int site_instance_id) { |
| 68 return items_.erase(Item(extension_id, process_id, site_instance_id)) > 0; |
| 50 } | 69 } |
| 51 | 70 |
| 52 int ProcessMap::Remove(int process_id) { | 71 int ProcessMap::RemoveAllFromProcess(int process_id) { |
| 53 int result = 0; | 72 int result = 0; |
| 54 for (ItemSet::const_iterator iter = items_.begin(); iter != items_.end(); ) { | 73 for (ItemSet::const_iterator iter = items_.begin(); iter != items_.end(); ) { |
| 55 if (iter->process_id == process_id) { | 74 if (iter->process_id == process_id) { |
| 56 items_.erase(iter++); | 75 items_.erase(iter++); |
| 57 ++result; | 76 ++result; |
| 58 } else { | 77 } else { |
| 59 ++iter; | 78 ++iter; |
| 60 } | 79 } |
| 61 } | 80 } |
| 62 return result; | 81 return result; |
| 63 } | 82 } |
| 64 | 83 |
| 65 bool ProcessMap::Contains(const std::string& extension_id, | 84 bool ProcessMap::Contains(const std::string& extension_id, |
| 66 int process_id) const { | 85 int process_id) const { |
| 67 return items_.find(Item(extension_id, process_id)) != items_.end(); | 86 for (ItemSet::const_iterator iter = items_.begin(); iter != items_.end(); |
| 87 ++iter) { |
| 88 if (iter->process_id == process_id && iter->extension_id == extension_id) |
| 89 return true; |
| 90 } |
| 91 return false; |
| 68 } | 92 } |
| 69 | 93 |
| 70 bool ProcessMap::Contains(int process_id) const { | 94 bool ProcessMap::Contains(int process_id) const { |
| 71 for (ItemSet::const_iterator iter = items_.begin(); iter != items_.end(); | 95 for (ItemSet::const_iterator iter = items_.begin(); iter != items_.end(); |
| 72 ++iter) { | 96 ++iter) { |
| 73 if (iter->process_id == process_id) | 97 if (iter->process_id == process_id) |
| 74 return true; | 98 return true; |
| 75 } | 99 } |
| 76 return false; | 100 return false; |
| 77 } | 101 } |
| 78 | 102 |
| 79 std::set<std::string> ProcessMap::GetExtensionsInProcess(int process_id) const { | 103 std::set<std::string> ProcessMap::GetExtensionsInProcess(int process_id) const { |
| 80 std::set<std::string> result; | 104 std::set<std::string> result; |
| 81 for (ItemSet::const_iterator iter = items_.begin(); iter != items_.end(); | 105 for (ItemSet::const_iterator iter = items_.begin(); iter != items_.end(); |
| 82 ++iter) { | 106 ++iter) { |
| 83 if (iter->process_id == process_id) | 107 if (iter->process_id == process_id) |
| 84 result.insert(iter->extension_id); | 108 result.insert(iter->extension_id); |
| 85 } | 109 } |
| 86 return result; | 110 return result; |
| 87 } | 111 } |
| 88 | 112 |
| 89 } // extensions | 113 } // extensions |
| OLD | NEW |