| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/public/browser/desktop_media_id.h" | 5 #include "content/public/browser/desktop_media_id.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 } | 25 } |
| 26 | 26 |
| 27 int RegisterWindow(aura::Window* window) { | 27 int RegisterWindow(aura::Window* window) { |
| 28 // First check if an Id is already assigned to the |window|. | 28 // First check if an Id is already assigned to the |window|. |
| 29 std::map<aura::Window*, int>::iterator it = window_to_id_map_.find(window); | 29 std::map<aura::Window*, int>::iterator it = window_to_id_map_.find(window); |
| 30 if (it != window_to_id_map_.end()) { | 30 if (it != window_to_id_map_.end()) { |
| 31 return it->second; | 31 return it->second; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // If the windows doesn't have an Id yet assign it. | 34 // If the windows doesn't have an Id yet assign it. |
| 35 int id = next_id_++; | 35 int id; |
| 36 do { |
| 37 id = next_id_; |
| 38 next_id_ = (next_id_ == INT_MAX) ? 1 : (next_id_ + 1); |
| 39 } while (id_to_window_map_.find(id) != id_to_window_map_.end()); |
| 40 |
| 36 window_to_id_map_[window] = id; | 41 window_to_id_map_[window] = id; |
| 37 id_to_window_map_[id] = window; | 42 id_to_window_map_[id] = window; |
| 38 window->AddObserver(this); | 43 window->AddObserver(this); |
| 39 return id; | 44 return id; |
| 40 } | 45 } |
| 41 | 46 |
| 42 aura::Window* GetWindowById(int id) { | 47 aura::Window* GetWindowById(int id) { |
| 43 std::map<int, aura::Window*>::iterator it = id_to_window_map_.find(id); | 48 std::map<int, aura::Window*>::iterator it = id_to_window_map_.find(id); |
| 44 return (it != id_to_window_map_.end()) ? it->second : NULL; | 49 return (it != id_to_window_map_.end()) ? it->second : NULL; |
| 45 } | 50 } |
| 46 | 51 |
| 47 private: | 52 private: |
| 48 friend struct DefaultSingletonTraits<AuraWindowRegistry>; | 53 friend struct DefaultSingletonTraits<AuraWindowRegistry>; |
| 49 | 54 |
| 50 AuraWindowRegistry() | 55 AuraWindowRegistry() |
| 51 : next_id_(0) { | 56 : next_id_(1) { |
| 52 } | 57 } |
| 53 virtual ~AuraWindowRegistry() {} | 58 virtual ~AuraWindowRegistry() {} |
| 54 | 59 |
| 55 // WindowObserver overrides. | 60 // WindowObserver overrides. |
| 56 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | 61 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
| 57 std::map<aura::Window*, int>::iterator it = window_to_id_map_.find(window); | 62 std::map<aura::Window*, int>::iterator it = window_to_id_map_.find(window); |
| 58 DCHECK(it != window_to_id_map_.end()); | 63 DCHECK(it != window_to_id_map_.end()); |
| 59 id_to_window_map_.erase(it->second); | 64 id_to_window_map_.erase(it->second); |
| 60 window_to_id_map_.erase(it); | 65 window_to_id_map_.erase(it); |
| 61 } | 66 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 143 } |
| 139 DCHECK(!prefix.empty()); | 144 DCHECK(!prefix.empty()); |
| 140 | 145 |
| 141 prefix.append(":"); | 146 prefix.append(":"); |
| 142 prefix.append(base::Int64ToString(id)); | 147 prefix.append(base::Int64ToString(id)); |
| 143 | 148 |
| 144 return prefix; | 149 return prefix; |
| 145 } | 150 } |
| 146 | 151 |
| 147 } // namespace content | 152 } // namespace content |
| OLD | NEW |