| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/open_from_clipboard/clipboard_recent_content.h" | 5 #include "components/open_from_clipboard/clipboard_recent_content.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "components/variations/variations_associated_data.h" | 9 #include "components/variations/variations_associated_data.h" |
| 10 #include "url/url_constants.h" | 10 #include "url/url_constants.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 ClipboardRecentContent* g_clipboard_recent_content = nullptr; | 13 ClipboardRecentContent* g_clipboard_recent_content = nullptr; |
| 14 | 14 |
| 15 // Schemes appropriate for suggestion by ClipboardRecentContent. | |
| 16 const char* kAuthorizedSchemes[] = { | |
| 17 url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, | |
| 18 // TODO(mpearson): add support for chrome:// URLs. Right now the scheme | |
| 19 // for that lives in content and is accessible via | |
| 20 // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme | |
| 21 // TODO(mpearson): when adding desktop support, add kFileScheme, kFtpScheme, | |
| 22 // and kGopherScheme. | |
| 23 }; | |
| 24 | |
| 25 } // namespace | 15 } // namespace |
| 26 | 16 |
| 27 ClipboardRecentContent::ClipboardRecentContent() {} | 17 ClipboardRecentContent::ClipboardRecentContent() {} |
| 28 | 18 |
| 29 ClipboardRecentContent::~ClipboardRecentContent() { | 19 ClipboardRecentContent::~ClipboardRecentContent() { |
| 30 } | 20 } |
| 31 | 21 |
| 32 // static | 22 // static |
| 33 ClipboardRecentContent* ClipboardRecentContent::GetInstance() { | 23 ClipboardRecentContent* ClipboardRecentContent::GetInstance() { |
| 34 return g_clipboard_recent_content; | 24 return g_clipboard_recent_content; |
| 35 } | 25 } |
| 36 | 26 |
| 37 // static | 27 // static |
| 38 void ClipboardRecentContent::SetInstance( | 28 void ClipboardRecentContent::SetInstance( |
| 39 std::unique_ptr<ClipboardRecentContent> new_instance) { | 29 std::unique_ptr<ClipboardRecentContent> new_instance) { |
| 40 delete g_clipboard_recent_content; | 30 delete g_clipboard_recent_content; |
| 41 g_clipboard_recent_content = new_instance.release(); | 31 g_clipboard_recent_content = new_instance.release(); |
| 42 } | 32 } |
| 43 | 33 |
| 44 // static | 34 // static |
| 45 bool ClipboardRecentContent::IsAppropriateSuggestion(const GURL& url) { | |
| 46 // Check to make sure it's a scheme we're willing to suggest. | |
| 47 for (const auto* authorized_scheme : kAuthorizedSchemes) { | |
| 48 if (url.SchemeIs(authorized_scheme)) | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 // Not a scheme we're allowed to return. | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 // static | |
| 57 base::TimeDelta ClipboardRecentContent::MaximumAgeOfClipboard() { | 35 base::TimeDelta ClipboardRecentContent::MaximumAgeOfClipboard() { |
| 58 // Identify the current setting for this parameter from the omnibox field | 36 // Identify the current setting for this parameter from the omnibox field |
| 59 // trial. | 37 // trial. |
| 60 std::string value_str = variations::GetVariationParamValue( | 38 std::string value_str = variations::GetVariationParamValue( |
| 61 "OmniboxBundledExperimentV1", "ClipboardURLMaximumAge"); | 39 "OmniboxBundledExperimentV1", "ClipboardURLMaximumAge"); |
| 62 // If the parameter is not set, use a 1 hour timeout. | 40 // If the parameter is not set, use a 1 hour timeout. |
| 63 if (value_str.empty()) | 41 if (value_str.empty()) |
| 64 return base::TimeDelta::FromHours(1); | 42 return base::TimeDelta::FromHours(1); |
| 65 // This is a best-effort conversion; we trust the hand-crafted parameters | 43 // This is a best-effort conversion; we trust the hand-crafted parameters |
| 66 // downloaded from the server to be perfect. There's no need for handle | 44 // downloaded from the server to be perfect. There's no need for handle |
| 67 // errors smartly. | 45 // errors smartly. |
| 68 int value; | 46 int value; |
| 69 // The value in the parameter is stored in seconds. | 47 // The value in the parameter is stored in seconds. |
| 70 base::StringToInt(value_str, &value); | 48 base::StringToInt(value_str, &value); |
| 71 return base::TimeDelta::FromSeconds(value); | 49 return base::TimeDelta::FromSeconds(value); |
| 72 } | 50 } |
| OLD | NEW |