Chromium Code Reviews| Index: content/public/browser/web_contents_media_capture_id.cc |
| diff --git a/content/browser/media/capture/web_contents_capture_util.cc b/content/public/browser/web_contents_media_capture_id.cc |
| similarity index 51% |
| rename from content/browser/media/capture/web_contents_capture_util.cc |
| rename to content/public/browser/web_contents_media_capture_id.cc |
| index 0edaf4a047d49df0af47ad674b54089a107340f7..034c842d169223524469d06be8da3c8ad17ccedf 100644 |
| --- a/content/browser/media/capture/web_contents_capture_util.cc |
| +++ b/content/public/browser/web_contents_media_capture_id.cc |
| @@ -2,7 +2,9 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "content/browser/media/capture/web_contents_capture_util.h" |
| +#include "content/public/browser/web_contents_media_capture_id.h" |
| + |
| +#include <tuple> |
| #include "base/basictypes.h" |
| #include "base/strings/string_number_conversions.h" |
| @@ -10,24 +12,63 @@ |
| #include "base/strings/string_util.h" |
| namespace content { |
| +const char kEnableFlag[] = "?throttling=auto"; |
| + |
| +bool WebContentsMediaCaptureId::operator<( |
|
miu
2015/12/14 20:21:08
Please account for |enable_auto_throttling| here.
GeorgeZ
2015/12/14 21:50:27
Done.
|
| + const WebContentsMediaCaptureId& other) const { |
| + return std::tie(render_process_id, main_render_frame_id) < |
| + std::tie(other.render_process_id, other.main_render_frame_id); |
| +} |
| + |
| +bool WebContentsMediaCaptureId::operator==( |
|
miu
2015/12/14 20:21:08
And need to account for |enable_auto_throttling| h
GeorgeZ
2015/12/14 21:50:27
Done.
|
| + const WebContentsMediaCaptureId& other) const { |
| + return std::tie(render_process_id, main_render_frame_id) == |
| + std::tie(other.render_process_id, other.main_render_frame_id); |
| +} |
| + |
| +bool WebContentsMediaCaptureId::is_null() const { |
| + return (render_process_id < 0) || (main_render_frame_id < 0); |
| +} |
| + |
| +std::string WebContentsMediaCaptureId::ToString() const { |
| + std::string s = kTabPrefix; |
| + s.append("://"); |
| + s.append(base::Int64ToString(render_process_id)); |
| + s.append(":"); |
| + s.append(base::Int64ToString(main_render_frame_id)); |
| + |
| + if (enable_auto_throttling) |
| + s.append(kEnableFlag); |
| + |
| + return s; |
| +} |
| + |
| +WebContentsMediaCaptureId WebContentsMediaCaptureId::Parse( |
| + const std::string& str) { |
| + int render_process_id; |
| + int main_render_frame_id; |
| + if (ExtractTabCaptureTarget(str, &render_process_id, &main_render_frame_id)) |
| + return WebContentsMediaCaptureId(render_process_id, main_render_frame_id); |
|
miu
2015/12/14 20:21:08
Please account for |enable_auto_throttling| here t
GeorgeZ
2015/12/14 21:50:27
Done.
|
| + else |
| + return WebContentsMediaCaptureId(); |
| +} |
| -bool WebContentsCaptureUtil::IsWebContentsDeviceId( |
| +bool WebContentsMediaCaptureId::IsWebContentsDeviceId( |
| const std::string& device_id) { |
| int ignored; |
| return ExtractTabCaptureTarget(device_id, &ignored, &ignored); |
| } |
| -bool WebContentsCaptureUtil::ExtractTabCaptureTarget( |
| +bool WebContentsMediaCaptureId::ExtractTabCaptureTarget( |
| const std::string& device_id_param, |
| int* render_process_id, |
| int* main_render_frame_id) { |
| - static const char kDeviceScheme[] = "web-contents-media-stream://"; |
| - if (!base::StartsWith(device_id_param, kDeviceScheme, |
| + if (!base::StartsWith(device_id_param, kTabPrefix, |
| base::CompareCase::SENSITIVE)) |
| return false; |
| - const std::string device_id = device_id_param.substr( |
| - arraysize(kDeviceScheme) - 1); |
| + const std::string device_id = |
| + device_id_param.substr(arraysize(kTabPrefix) - 1); |
|
miu
2015/12/14 20:21:08
With the change from kDeviceScheme to kTabPrefix,
GeorgeZ
2015/12/14 21:50:27
Good catch
|
| const size_t sep_pos = device_id.find(':'); |
| if (sep_pos == std::string::npos) |
| @@ -44,7 +85,7 @@ bool WebContentsCaptureUtil::ExtractTabCaptureTarget( |
| base::StringToInt(component2, main_render_frame_id)); |
| } |
| -bool WebContentsCaptureUtil::IsAutoThrottlingOptionSet( |
| +bool WebContentsMediaCaptureId::IsAutoThrottlingOptionSet( |
| const std::string& device_id) { |
| if (!IsWebContentsDeviceId(device_id)) |
| return false; |
| @@ -57,7 +98,6 @@ bool WebContentsCaptureUtil::IsAutoThrottlingOptionSet( |
| return false; |
| const base::StringPiece component(device_id.data() + option_pos, |
| device_id.length() - option_pos); |
| - static const char kEnableFlag[] = "?throttling=auto"; |
| return component.compare(kEnableFlag) == 0; |
| } |