OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/tab_capture/tab_capture_registry.h" | 5 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
6 | 6 |
7 #include <utility> | |
8 | |
7 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
8 #include "chrome/browser/extensions/event_names.h" | 10 #include "chrome/browser/extensions/event_names.h" |
9 #include "chrome/browser/extensions/event_router.h" | 11 #include "chrome/browser/extensions/event_router.h" |
10 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
11 #include "chrome/browser/media/media_internals.h" | 13 #include "chrome/browser/media/media_internals.h" |
12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_dependency_manager.h" | 15 #include "chrome/browser/profiles/profile_dependency_manager.h" |
14 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
16 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 default: | 72 default: |
71 // TODO(justinlin): Implement muted state notification. | 73 // TODO(justinlin): Implement muted state notification. |
72 break; | 74 break; |
73 } | 75 } |
74 | 76 |
75 if (state == tab_capture::TAB_CAPTURE_TAB_CAPTURE_STATE_NONE) { | 77 if (state == tab_capture::TAB_CAPTURE_TAB_CAPTURE_STATE_NONE) { |
76 // This is a state we don't handle. | 78 // This is a state we don't handle. |
77 return; | 79 return; |
78 } | 80 } |
79 | 81 |
80 TabCaptureRegistry::TabCaptureRequest& request_info = requests_[key]; | 82 TabCaptureRegistry::TabCaptureRequest& request_info = |
83 requests_.find(key)->second; | |
Matt Perry
2013/01/04 21:17:18
This is not the same as the old code. If |key| is
justinlin
2013/01/04 22:10:52
Done. Right, there's a check above to make sure th
| |
81 request_info.status = state; | 84 request_info.status = state; |
82 | 85 |
83 scoped_ptr<tab_capture::CaptureInfo> info(new tab_capture::CaptureInfo()); | 86 scoped_ptr<tab_capture::CaptureInfo> info(new tab_capture::CaptureInfo()); |
84 info->tab_id = request_info.tab_id; | 87 info->tab_id = request_info.tab_id; |
85 info->status = request_info.status; | 88 info->status = request_info.status; |
86 | 89 |
87 scoped_ptr<base::ListValue> args(new ListValue()); | 90 scoped_ptr<base::ListValue> args(new ListValue()); |
88 args->Append(info->ToValue().release()); | 91 args->Append(info->ToValue().release()); |
89 scoped_ptr<Event> event(new Event( | 92 scoped_ptr<Event> event(new Event( |
90 events::kOnTabCaptureStatusChanged, args.Pass())); | 93 events::kOnTabCaptureStatusChanged, args.Pass())); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 } | 126 } |
124 } | 127 } |
125 break; | 128 break; |
126 } | 129 } |
127 } | 130 } |
128 } | 131 } |
129 | 132 |
130 bool TabCaptureRegistry::AddRequest(const std::pair<int, int> key, | 133 bool TabCaptureRegistry::AddRequest(const std::pair<int, int> key, |
131 const TabCaptureRequest& request) { | 134 const TabCaptureRequest& request) { |
132 // Currently, we do not allow multiple active captures for same tab. | 135 // Currently, we do not allow multiple active captures for same tab. |
133 if (requests_.find(key) != requests_.end()) | 136 DeviceCaptureRequestMap::iterator it = requests_.find(key); |
134 if (requests_[key].status != | 137 if (it != requests_.end()) { |
135 tab_capture::TAB_CAPTURE_TAB_CAPTURE_STATE_STOPPED && | 138 tab_capture::TabCaptureState state = it->second.status; |
kmadhusu
2013/01/04 21:01:01
You can avoid copying by using a const ref.
justinlin
2013/01/04 22:10:52
Done.
| |
136 requests_[key].status != | 139 if (state != tab_capture::TAB_CAPTURE_TAB_CAPTURE_STATE_STOPPED && |
137 tab_capture::TAB_CAPTURE_TAB_CAPTURE_STATE_ERROR) | 140 state != tab_capture::TAB_CAPTURE_TAB_CAPTURE_STATE_ERROR) |
138 return false; | 141 return false; |
139 requests_[key] = request; | 142 } |
143 requests_.insert(std::make_pair(key, request)); | |
140 return true; | 144 return true; |
141 } | 145 } |
142 | 146 |
143 bool TabCaptureRegistry::VerifyRequest(int render_process_id, | 147 bool TabCaptureRegistry::VerifyRequest(int render_process_id, |
144 int render_view_id) { | 148 int render_view_id) { |
145 return requests_.find(std::make_pair( | 149 return requests_.find(std::make_pair( |
146 render_process_id, render_view_id)) != requests_.end(); | 150 render_process_id, render_view_id)) != requests_.end(); |
147 } | 151 } |
148 | 152 |
149 void TabCaptureRegistry::MediaObserverProxy::Attach( | 153 void TabCaptureRegistry::MediaObserverProxy::Attach( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 const content::MediaStreamDevice& device, | 201 const content::MediaStreamDevice& device, |
198 const content::MediaRequestState new_state) { | 202 const content::MediaRequestState new_state) { |
199 if (handler_) | 203 if (handler_) |
200 handler_->HandleRequestUpdateOnUIThread(render_process_id, | 204 handler_->HandleRequestUpdateOnUIThread(render_process_id, |
201 render_view_id, | 205 render_view_id, |
202 device, | 206 device, |
203 new_state); | 207 new_state); |
204 } | 208 } |
205 | 209 |
206 } // namespace extensions | 210 } // namespace extensions |
OLD | NEW |