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

Side by Side Diff: content/public/browser/desktop_media_id.cc

Issue 499813002: Update AuraWindowRegistry to create only positive window IDs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698