| 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" |
| 8 #include "base/time/time.h" |
| 9 #include "components/variations/variations_associated_data.h" |
| 7 #include "url/url_constants.h" | 10 #include "url/url_constants.h" |
| 8 | 11 |
| 9 namespace { | 12 namespace { |
| 10 ClipboardRecentContent* g_clipboard_recent_content = nullptr; | 13 ClipboardRecentContent* g_clipboard_recent_content = nullptr; |
| 11 | 14 |
| 12 // Schemes appropriate for suggestion by ClipboardRecentContent. | 15 // Schemes appropriate for suggestion by ClipboardRecentContent. |
| 13 const char* kAuthorizedSchemes[] = { | 16 const char* kAuthorizedSchemes[] = { |
| 14 url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, | 17 url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, |
| 15 // TODO(mpearson): add support for chrome:// URLs. Right now the scheme | 18 // TODO(mpearson): add support for chrome:// URLs. Right now the scheme |
| 16 // for that lives in content and is accessible via | 19 // for that lives in content and is accessible via |
| (...skipping 24 matching lines...) Expand all Loading... |
| 41 bool ClipboardRecentContent::IsAppropriateSuggestion(const GURL& url) { | 44 bool ClipboardRecentContent::IsAppropriateSuggestion(const GURL& url) { |
| 42 // Check to make sure it's a scheme we're willing to suggest. | 45 // Check to make sure it's a scheme we're willing to suggest. |
| 43 for (const auto* authorized_scheme : kAuthorizedSchemes) { | 46 for (const auto* authorized_scheme : kAuthorizedSchemes) { |
| 44 if (url.SchemeIs(authorized_scheme)) | 47 if (url.SchemeIs(authorized_scheme)) |
| 45 return true; | 48 return true; |
| 46 } | 49 } |
| 47 | 50 |
| 48 // Not a scheme we're allowed to return. | 51 // Not a scheme we're allowed to return. |
| 49 return false; | 52 return false; |
| 50 } | 53 } |
| 54 |
| 55 // static |
| 56 base::TimeDelta ClipboardRecentContent::MaximumAgeOfClipboard() { |
| 57 // Identify the current setting for this parameter from the omnibox field |
| 58 // trial. |
| 59 std::string value_str = variations::GetVariationParamValue( |
| 60 "OmniboxBundledExperimentV1", "ClipboardURLMaximumAge"); |
| 61 // If the parameter is not set, use a 1 hour timeout. |
| 62 if (value_str.empty()) |
| 63 return base::TimeDelta::FromHours(1); |
| 64 // This is a best-effort conversion; we trust the hand-crafted parameters |
| 65 // downloaded from the server to be perfect. There's no need for handle |
| 66 // errors smartly. |
| 67 int value; |
| 68 // The value in the parameter is stored in seconds. |
| 69 base::StringToInt(value_str, &value); |
| 70 return base::TimeDelta::FromSeconds(value); |
| 71 } |
| OLD | NEW |