Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: chrome/browser/ui/views/chrome_to_mobile_bubble_view.cc

Issue 10808068: Store ChromeToMobile device list and timestamp prefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add GetMobiles ownership/lifetime comment. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ui/views/chrome_to_mobile_bubble_view.h" 5 #include "chrome/browser/ui/views/chrome_to_mobile_bubble_view.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); 218 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
219 layout->StartRow(0, 0 /*single_column_set_id*/); 219 layout->StartRow(0, 0 /*single_column_set_id*/);
220 layout->AddView(error_label); 220 layout->AddView(error_label);
221 SizeToContents(); 221 SizeToContents();
222 } 222 }
223 223
224 Layout(); 224 Layout();
225 } 225 }
226 226
227 void ChromeToMobileBubbleView::Init() { 227 void ChromeToMobileBubbleView::Init() {
228 DCHECK(service_->HasMobiles());
229 service_->LogMetric(ChromeToMobileService::BUBBLE_SHOWN);
230
228 GridLayout* layout = new GridLayout(this); 231 GridLayout* layout = new GridLayout(this);
229 SetLayoutManager(layout); 232 SetLayoutManager(layout);
230 233
231 const size_t single_column_set_id = 0; 234 const size_t single_column_set_id = 0;
232 views::ColumnSet* cs = layout->AddColumnSet(single_column_set_id); 235 views::ColumnSet* cs = layout->AddColumnSet(single_column_set_id);
233 cs->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, 236 cs->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,
234 GridLayout::USE_PREF, 0, 0); 237 GridLayout::USE_PREF, 0, 0);
235 cs->AddPaddingColumn(1, 0); 238 cs->AddPaddingColumn(1, 0);
236 239
237 const size_t button_column_set_id = 1; 240 const size_t button_column_set_id = 1;
238 cs = layout->AddColumnSet(button_column_set_id); 241 cs = layout->AddColumnSet(button_column_set_id);
239 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 242 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
240 GridLayout::USE_PREF, 0, 0); 243 GridLayout::USE_PREF, 0, 0);
241 cs->AddPaddingColumn(1, 0); 244 cs->AddPaddingColumn(1, 0);
242 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 245 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
243 GridLayout::USE_PREF, 0, 0); 246 GridLayout::USE_PREF, 0, 0);
244 // Subtract 2px for the natural button padding and to correspond with row 247 // Subtract 2px for the natural button padding and to correspond with row
245 // separation height; like BookmarkBubbleView. 248 // separation height; like BookmarkBubbleView.
246 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); 249 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2);
247 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, 250 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
248 GridLayout::USE_PREF, 0, 0); 251 GridLayout::USE_PREF, 0, 0);
249 252
250 // Get the list of mobile devices.
251 const ListValue& mobiles = service_->mobiles();
252 DCHECK(!mobiles.empty());
253
254 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 253 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
255 views::Label* title_label = new views::Label(); 254 views::Label* title_label = new views::Label();
256 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); 255 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
257 title_label->SetEnabledColor(kTitleColor); 256 title_label->SetEnabledColor(kTitleColor);
258 layout->StartRow(0, single_column_set_id); 257 layout->StartRow(0, single_column_set_id);
259 layout->AddView(title_label); 258 layout->AddView(title_label);
260 259
261 if (mobiles.GetSize() == 1) { 260 const ListValue* mobiles = service_->GetMobiles();
261 if (mobiles->GetSize() == 1) {
262 string16 name; 262 string16 name;
263 DictionaryValue* mobile = NULL; 263 DictionaryValue* mobile = NULL;
264 if (mobiles.GetDictionary(0, &mobile) && mobile->GetString("name", &name)) { 264 if (mobiles->GetDictionary(0, &mobile) &&
265 mobile->GetString("name", &name)) {
265 title_label->SetText(l10n_util::GetStringFUTF16( 266 title_label->SetText(l10n_util::GetStringFUTF16(
266 IDS_CHROME_TO_MOBILE_BUBBLE_SINGLE_TITLE, name)); 267 IDS_CHROME_TO_MOBILE_BUBBLE_SINGLE_TITLE, name));
267 } else { 268 } else {
268 NOTREACHED(); 269 NOTREACHED();
269 } 270 }
270 } else { 271 } else {
271 title_label->SetText(l10n_util::GetStringUTF16( 272 title_label->SetText(l10n_util::GetStringUTF16(
272 IDS_CHROME_TO_MOBILE_BUBBLE_MULTI_TITLE)); 273 IDS_CHROME_TO_MOBILE_BUBBLE_MULTI_TITLE));
273 274
274 string16 name; 275 string16 name;
275 DictionaryValue* mobile = NULL; 276 DictionaryValue* mobile = NULL;
276 views::RadioButton* radio = NULL; 277 views::RadioButton* radio = NULL;
277 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); 278 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
278 for (size_t index = 0; index < mobiles.GetSize(); ++index) { 279 for (size_t index = 0; index < mobiles->GetSize(); ++index) {
279 if (mobiles.GetDictionary(index, &mobile) && 280 if (mobiles->GetDictionary(index, &mobile) &&
280 mobile->GetString("name", &name)) { 281 mobile->GetString("name", &name)) {
281 radio = new views::RadioButton(name, 0); 282 radio = new views::RadioButton(name, 0);
282 radio->SetEnabledColor(SK_ColorBLACK); 283 radio->SetEnabledColor(SK_ColorBLACK);
283 radio->SetHoverColor(SK_ColorBLACK); 284 radio->SetHoverColor(SK_ColorBLACK);
284 radio_buttons_.push_back(radio); 285 radio_buttons_.push_back(radio);
285 layout->StartRow(0, single_column_set_id); 286 layout->StartRow(0, single_column_set_id);
286 layout->AddView(radio); 287 layout->AddView(radio);
287 } else { 288 } else {
288 NOTREACHED(); 289 NOTREACHED();
289 } 290 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 324
324 ChromeToMobileBubbleView::ChromeToMobileBubbleView(views::View* anchor_view, 325 ChromeToMobileBubbleView::ChromeToMobileBubbleView(views::View* anchor_view,
325 Browser* browser) 326 Browser* browser)
326 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 327 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
327 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 328 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
328 browser_(browser), 329 browser_(browser),
329 service_(ChromeToMobileServiceFactory::GetForProfile(browser->profile())), 330 service_(ChromeToMobileServiceFactory::GetForProfile(browser->profile())),
330 send_copy_(NULL), 331 send_copy_(NULL),
331 send_(NULL), 332 send_(NULL),
332 cancel_(NULL) { 333 cancel_(NULL) {
333 service_->LogMetric(ChromeToMobileService::BUBBLE_SHOWN);
334
335 // Generate the MHTML snapshot now to report its size in the bubble. 334 // Generate the MHTML snapshot now to report its size in the bubble.
336 service_->GenerateSnapshot(browser_, weak_ptr_factory_.GetWeakPtr()); 335 service_->GenerateSnapshot(browser_, weak_ptr_factory_.GetWeakPtr());
337 336
338 // Request a mobile device list update. 337 // Request a mobile device list update.
339 service_->RequestMobileListUpdate(); 338 service_->RequestMobileListUpdate();
340 } 339 }
341 340
342 void ChromeToMobileBubbleView::LinkClicked(views::Link* source, 341 void ChromeToMobileBubbleView::LinkClicked(views::Link* source,
343 int event_flags) { 342 int event_flags) {
344 service_->LearnMore(browser_); 343 service_->LearnMore(browser_);
345 GetWidget()->Close(); 344 GetWidget()->Close();
346 } 345 }
347 346
348 void ChromeToMobileBubbleView::HandleButtonPressed(views::Button* sender) { 347 void ChromeToMobileBubbleView::HandleButtonPressed(views::Button* sender) {
349 if (sender == send_) 348 if (sender == send_)
350 Send(); 349 Send();
351 else if (sender == cancel_) 350 else if (sender == cancel_)
352 GetWidget()->Close(); 351 GetWidget()->Close();
353 } 352 }
354 353
355 void ChromeToMobileBubbleView::Send() { 354 void ChromeToMobileBubbleView::Send() {
356 // TODO(msw): Handle updates to the mobile list while the bubble is open. 355 // TODO(msw): Handle updates to the mobile list while the bubble is open.
357 const ListValue& mobiles = service_->mobiles(); 356 const ListValue* mobiles = service_->GetMobiles();
358 size_t selected_index = 0; 357 size_t selected_index = 0;
359 if (mobiles.GetSize() > 1) { 358 if (mobiles->GetSize() > 1) {
360 DCHECK_EQ(mobiles.GetSize(), radio_buttons_.size()); 359 DCHECK_EQ(mobiles->GetSize(), radio_buttons_.size());
361 for (; selected_index < radio_buttons_.size(); ++selected_index) { 360 for (; selected_index < radio_buttons_.size(); ++selected_index) {
362 if (radio_buttons_[selected_index]->checked()) 361 if (radio_buttons_[selected_index]->checked())
363 break; 362 break;
364 } 363 }
365 } else { 364 } else {
366 DCHECK(radio_buttons_.empty()); 365 DCHECK(radio_buttons_.empty());
367 } 366 }
368 367
369 DictionaryValue* mobile = NULL; 368 DictionaryValue* mobile = NULL;
370 if (mobiles.GetDictionary(selected_index, &mobile)) { 369 if (mobiles->GetDictionary(selected_index, &mobile)) {
371 FilePath snapshot = send_copy_->checked() ? snapshot_path_ : FilePath(); 370 FilePath snapshot = send_copy_->checked() ? snapshot_path_ : FilePath();
372 service_->SendToMobile(*mobile, snapshot, browser_, 371 service_->SendToMobile(*mobile, snapshot, browser_,
373 weak_ptr_factory_.GetWeakPtr()); 372 weak_ptr_factory_.GetWeakPtr());
374 } else { 373 } else {
375 NOTREACHED(); 374 NOTREACHED();
376 } 375 }
377 376
378 // Update the view's contents to show the "Sending..." progress animation. 377 // Update the view's contents to show the "Sending..." progress animation.
379 cancel_->SetEnabled(false); 378 cancel_->SetEnabled(false);
380 send_->SetEnabled(false); 379 send_->SetEnabled(false);
381 send_->set_alignment(views::TextButtonBase::ALIGN_LEFT); 380 send_->set_alignment(views::TextButtonBase::ALIGN_LEFT);
382 progress_animation_.reset(new ui::ThrobAnimation(this)); 381 progress_animation_.reset(new ui::ThrobAnimation(this));
383 progress_animation_->SetDuration(kProgressThrobDurationMS); 382 progress_animation_->SetDuration(kProgressThrobDurationMS);
384 progress_animation_->StartThrobbing(-1); 383 progress_animation_->StartThrobbing(-1);
385 } 384 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/location_bar_view_gtk.cc ('k') | chrome/browser/ui/views/location_bar/location_bar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698