Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / proxy_settings_dialog.cc
blobf106a5472a5dc0131dc5afd2fb69a074b8a7c437
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/proxy_settings_dialog.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/chromeos/login/helper.h"
11 #include "chrome/common/url_constants.h"
12 #include "chromeos/network/network_state.h"
13 #include "chromeos/network/shill_property_util.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_service.h"
16 #include "grit/generated_resources.h"
17 #include "net/base/escape.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/gfx/rect.h"
21 #include "ui/gfx/size.h"
23 namespace {
25 // Hints for size of proxy settings dialog.
26 const int kProxySettingsDialogReasonableWidth = 626;
27 const int kProxySettingsDialogReasonableHeight = 525;
28 const float kProxySettingsDialogReasonableWidthRatio = 0.4f;
29 const float kProxySettingsDialogReasonableHeightRatio = 0.4f;
31 const char* kProxySettingsURLParam = "?network=%s";
33 int CalculateSize(int screen_size, int min_comfortable, float desired_ratio) {
34 int desired_size = static_cast<int>(desired_ratio * screen_size);
35 desired_size = std::max(min_comfortable, desired_size);
36 return std::min(screen_size, desired_size);
39 GURL GetURLForProxySettings(const std::string& service_path) {
40 std::string url(chrome::kChromeUIProxySettingsURL);
41 url += base::StringPrintf(
42 kProxySettingsURLParam,
43 net::EscapeUrlEncodedData(service_path, true).c_str());
44 return GURL(url);
47 } // namespace
49 namespace chromeos {
51 // static
52 int ProxySettingsDialog::instance_count_ = 0;
54 ProxySettingsDialog::ProxySettingsDialog(Profile* profile,
55 const NetworkState& network,
56 LoginWebDialog::Delegate* delegate,
57 gfx::NativeWindow window)
58 : LoginWebDialog(profile,
59 delegate,
60 window,
61 base::string16(),
62 GetURLForProxySettings(network.path()),
63 LoginWebDialog::STYLE_BUBBLE) {
64 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
65 ++instance_count_;
67 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
68 SetDialogSize(CalculateSize(screen_bounds.width(),
69 kProxySettingsDialogReasonableWidth,
70 kProxySettingsDialogReasonableWidthRatio),
71 CalculateSize(screen_bounds.height(),
72 kProxySettingsDialogReasonableHeight,
73 kProxySettingsDialogReasonableHeightRatio));
75 std::string network_name = network.name();
76 if (network_name.empty() && network.Matches(NetworkTypePattern::Ethernet())) {
77 network_name =
78 l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
81 SetDialogTitle(l10n_util::GetStringFUTF16(IDS_PROXY_PAGE_TITLE_FORMAT,
82 base::ASCIIToUTF16(network_name)));
85 ProxySettingsDialog::~ProxySettingsDialog() {
86 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
87 --instance_count_;
90 void ProxySettingsDialog::OnDialogClosed(const std::string& json_retval) {
91 LoginWebDialog::OnDialogClosed(json_retval);
92 content::NotificationService::current()->Notify(
93 chrome::NOTIFICATION_LOGIN_PROXY_CHANGED,
94 content::NotificationService::AllSources(),
95 content::NotificationService::NoDetails());
98 bool ProxySettingsDialog::IsShown() {
99 return instance_count_ > 0;
102 } // namespace chromeos