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" | 7 #include "url/url_constants.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 ClipboardRecentContent* g_clipboard_recent_content = nullptr; | |
| 11 | |
| 12 // Schemes appropriate for suggestion by ClipboardRecentContent. | 10 // Schemes appropriate for suggestion by ClipboardRecentContent. |
| 13 const char* kAuthorizedSchemes[] = { | 11 const char* kAuthorizedSchemes[] = { |
| 14 url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, | 12 url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, |
| 15 // TODO(mpearson): add support for chrome:// URLs. Right now the scheme | 13 // TODO(mpearson): add support for chrome:// URLs. Right now the scheme |
| 16 // for that lives in content and is accessible via | 14 // for that lives in content and is accessible via |
| 17 // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme | 15 // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme |
| 18 // TODO(mpearson): when adding desktop support, add kFileScheme, kFtpScheme, | 16 // TODO(mpearson): when adding desktop support, add kFileScheme, kFtpScheme, |
| 19 // and kGopherScheme. | 17 // and kGopherScheme. |
| 20 }; | 18 }; |
| 21 | 19 |
| 22 } // namespace | 20 } // namespace |
| 23 | 21 |
| 24 ClipboardRecentContent::ClipboardRecentContent() {} | 22 ClipboardRecentContent::ClipboardRecentContent() {} |
| 25 | 23 |
| 26 ClipboardRecentContent::~ClipboardRecentContent() { | 24 ClipboardRecentContent::~ClipboardRecentContent() { |
| 27 g_clipboard_recent_content = nullptr; | |
| 28 } | 25 } |
| 29 | 26 |
| 30 // static | 27 // static |
| 31 ClipboardRecentContent* ClipboardRecentContent::GetInstance() { | 28 ClipboardRecentContent* ClipboardRecentContent::GetInstance() { |
| 32 return g_clipboard_recent_content; | 29 return UniquePtrToInstance()->get(); |
| 33 } | 30 } |
| 34 | 31 |
| 35 // static | 32 // static |
| 36 void ClipboardRecentContent::SetInstance(ClipboardRecentContent* instance) { | 33 void ClipboardRecentContent::SetInstance( |
| 37 g_clipboard_recent_content = instance; | 34 std::unique_ptr<ClipboardRecentContent> new_instance) { |
| 35 (*UniquePtrToInstance()) = std::move(new_instance); | |
| 38 } | 36 } |
| 39 | 37 |
| 40 // static | 38 // static |
| 41 bool ClipboardRecentContent::IsAppropriateSuggestion(const GURL& url) { | 39 bool ClipboardRecentContent::IsAppropriateSuggestion(const GURL& url) { |
| 42 // Check to make sure it's a scheme we're willing to suggest. | 40 // Check to make sure it's a scheme we're willing to suggest. |
| 43 for (const auto* authorized_scheme : kAuthorizedSchemes) { | 41 for (const auto* authorized_scheme : kAuthorizedSchemes) { |
| 44 if (url.SchemeIs(authorized_scheme)) | 42 if (url.SchemeIs(authorized_scheme)) |
| 45 return true; | 43 return true; |
| 46 } | 44 } |
| 47 | 45 |
| 48 // Not a scheme we're allowed to return. | 46 // Not a scheme we're allowed to return. |
| 49 return false; | 47 return false; |
| 50 } | 48 } |
| 49 | |
| 50 // static | |
| 51 std::unique_ptr<ClipboardRecentContent>* | |
| 52 ClipboardRecentContent::UniquePtrToInstance() { | |
|
Peter Kasting
2017/04/10 21:59:22
Why do this as a static member function instead of
Mark P
2017/04/10 22:05:22
jif@ wrote:
"I don't think we are allowed to have
Peter Kasting
2017/04/10 22:18:34
On thinking about it more I think both methods are
Mark P
2017/04/10 23:10:14
Okay.
This is also fine with me. Done.
| |
| 53 static std::unique_ptr<ClipboardRecentContent> instance; | |
| 54 return &instance; | |
| 55 } | |
| OLD | NEW |