Chromium Code Reviews| 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 "url/url_constants.h" | |
| 8 | |
| 7 namespace { | 9 namespace { |
| 8 ClipboardRecentContent* g_clipboard_recent_content = nullptr; | 10 ClipboardRecentContent* g_clipboard_recent_content = nullptr; |
| 9 } | 11 |
| 12 // Schemes appropriate for suggestion by ClipboardRecentContent. | |
| 13 const char* kAuthorizedSchemes[] = { | |
| 14 url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, | |
| 15 // TODO(mpearson): add support for chrome:// URLs. Right now the scheme | |
| 16 // for that lives in content and is accessible via | |
| 17 // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme | |
| 18 // TODO(mpearson): when adding desktop support, add kFileScheme, kFtpScheme, | |
| 19 // and kGopherScheme. | |
| 20 }; | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 const base::TimeDelta ClipboardRecentContent::kMaximumAgeOfClipboard = | |
|
dcheng
2017/04/02 05:04:03
Does this generate a static initializer? (The cons
Mark P
2017/04/02 05:33:56
Changed to constexpr.
| |
| 25 base::TimeDelta::FromHours(3); | |
| 10 | 26 |
| 11 ClipboardRecentContent::ClipboardRecentContent() {} | 27 ClipboardRecentContent::ClipboardRecentContent() {} |
| 12 | 28 |
| 13 ClipboardRecentContent::~ClipboardRecentContent() {} | 29 ClipboardRecentContent::~ClipboardRecentContent() {} |
| 14 | 30 |
| 15 // static | 31 // static |
| 16 ClipboardRecentContent* ClipboardRecentContent::GetInstance() { | 32 ClipboardRecentContent* ClipboardRecentContent::GetInstance() { |
| 17 return g_clipboard_recent_content; | 33 return g_clipboard_recent_content; |
| 18 } | 34 } |
| 19 | 35 |
| 20 // static | 36 // static |
| 21 void ClipboardRecentContent::SetInstance(ClipboardRecentContent* instance) { | 37 void ClipboardRecentContent::SetInstance(ClipboardRecentContent* instance) { |
| 22 g_clipboard_recent_content = instance; | 38 g_clipboard_recent_content = instance; |
| 23 } | 39 } |
| 40 | |
| 41 // static | |
| 42 bool ClipboardRecentContent::IsAppropriateSuggestion(const GURL& url) { | |
| 43 // Check to make sure it's a scheme we're willing to suggest. | |
| 44 for (size_t i = 0; i < arraysize(kAuthorizedSchemes); ++i) { | |
|
dcheng
2017/04/02 05:04:03
Alternatively:
for (const auto* authorized_scheme
Mark P
2017/04/02 05:33:56
Nice. Done.
| |
| 45 if (url.SchemeIs(kAuthorizedSchemes[i])) | |
| 46 return true; | |
| 47 } | |
| 48 | |
| 49 // Not a scheme we're allowed to return. | |
| 50 return false; | |
| 51 } | |
| OLD | NEW |