| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/devtools/remote_debugging_server.h" | 5 #include "chrome/browser/devtools/remote_debugging_server.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/devtools/devtools_window.h" | 14 #include "chrome/browser/devtools/devtools_window.h" |
| 15 #include "chrome/browser/history/top_sites_factory.h" | 15 #include "chrome/browser/history/top_sites_factory.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_iterator.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/common/chrome_content_client.h" | 19 #include "chrome/common/chrome_content_client.h" |
| 20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 21 #include "components/devtools_http_handler/devtools_http_handler.h" | 21 #include "components/devtools_http_handler/devtools_http_handler.h" |
| 22 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" | 22 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" |
| 23 #include "components/history/core/browser/top_sites.h" | 23 #include "components/history/core/browser/top_sites.h" |
| 24 #include "components/version_info/version_info.h" | 24 #include "components/version_info/version_info.h" |
| 25 #include "content/public/browser/devtools_frontend_host.h" | 25 #include "content/public/browser/devtools_frontend_host.h" |
| 26 #include "grit/browser_resources.h" | 26 #include "grit/browser_resources.h" |
| 27 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 28 #include "net/socket/tcp_server_socket.h" | 28 #include "net/socket/tcp_server_socket.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 ChromeDevToolsHttpHandlerDelegate::ChromeDevToolsHttpHandlerDelegate() { | 99 ChromeDevToolsHttpHandlerDelegate::ChromeDevToolsHttpHandlerDelegate() { |
| 100 } | 100 } |
| 101 | 101 |
| 102 ChromeDevToolsHttpHandlerDelegate::~ChromeDevToolsHttpHandlerDelegate() { | 102 ChromeDevToolsHttpHandlerDelegate::~ChromeDevToolsHttpHandlerDelegate() { |
| 103 } | 103 } |
| 104 | 104 |
| 105 std::string ChromeDevToolsHttpHandlerDelegate::GetDiscoveryPageHTML() { | 105 std::string ChromeDevToolsHttpHandlerDelegate::GetDiscoveryPageHTML() { |
| 106 std::set<Profile*> profiles; | 106 std::set<Profile*> profiles; |
| 107 for (chrome::BrowserIterator it; !it.done(); it.Next()) | 107 for (auto& browser : *BrowserList::GetInstance()) |
| 108 profiles.insert((*it)->profile()); | 108 profiles.insert(browser->profile()); |
| 109 | 109 |
| 110 for (std::set<Profile*>::iterator it = profiles.begin(); | 110 for (std::set<Profile*>::iterator it = profiles.begin(); |
| 111 it != profiles.end(); ++it) { | 111 it != profiles.end(); ++it) { |
| 112 scoped_refptr<history::TopSites> ts = TopSitesFactory::GetForProfile(*it); | 112 scoped_refptr<history::TopSites> ts = TopSitesFactory::GetForProfile(*it); |
| 113 if (ts) { | 113 if (ts) { |
| 114 // TopSites updates itself after a delay. Ask TopSites to update itself | 114 // TopSites updates itself after a delay. Ask TopSites to update itself |
| 115 // when we're about to show the remote debugging landing page. | 115 // when we're about to show the remote debugging landing page. |
| 116 ts->SyncWithHistory(); | 116 ts->SyncWithHistory(); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 119 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 120 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); | 120 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 std::string ChromeDevToolsHttpHandlerDelegate::GetFrontendResource( | 123 std::string ChromeDevToolsHttpHandlerDelegate::GetFrontendResource( |
| 124 const std::string& path) { | 124 const std::string& path) { |
| 125 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); | 125 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 std::string ChromeDevToolsHttpHandlerDelegate::GetPageThumbnailData( | 128 std::string ChromeDevToolsHttpHandlerDelegate::GetPageThumbnailData( |
| 129 const GURL& url) { | 129 const GURL& url) { |
| 130 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 130 for (auto& browser : *BrowserList::GetInstance()) { |
| 131 Profile* profile = (*it)->profile(); | 131 Profile* profile = browser->profile(); |
| 132 scoped_refptr<history::TopSites> top_sites = | 132 scoped_refptr<history::TopSites> top_sites = |
| 133 TopSitesFactory::GetForProfile(profile); | 133 TopSitesFactory::GetForProfile(profile); |
| 134 if (!top_sites) | 134 if (!top_sites) |
| 135 continue; | 135 continue; |
| 136 scoped_refptr<base::RefCountedMemory> data; | 136 scoped_refptr<base::RefCountedMemory> data; |
| 137 if (top_sites->GetPageThumbnail(url, false, &data)) | 137 if (top_sites->GetPageThumbnail(url, false, &data)) |
| 138 return std::string(data->front_as<char>(), data->size()); | 138 return std::string(data->front_as<char>(), data->size()); |
| 139 } | 139 } |
| 140 return std::string(); | 140 return std::string(); |
| 141 } | 141 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 debug_frontend_dir, | 179 debug_frontend_dir, |
| 180 version_info::GetProductNameAndVersionForUserAgent(), | 180 version_info::GetProductNameAndVersionForUserAgent(), |
| 181 ::GetUserAgent())); | 181 ::GetUserAgent())); |
| 182 } | 182 } |
| 183 | 183 |
| 184 RemoteDebuggingServer::~RemoteDebuggingServer() { | 184 RemoteDebuggingServer::~RemoteDebuggingServer() { |
| 185 // Ensure Profile is alive, because the whole DevTools subsystem | 185 // Ensure Profile is alive, because the whole DevTools subsystem |
| 186 // accesses it during shutdown. | 186 // accesses it during shutdown. |
| 187 DCHECK(g_browser_process->profile_manager()); | 187 DCHECK(g_browser_process->profile_manager()); |
| 188 } | 188 } |
| OLD | NEW |