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

Side by Side Diff: chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller.mm

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 #import "chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller.h"
6 6
7 #include "base/mac/mac_util.h" 7 #include "base/mac/mac_util.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/chrome_to_mobile_service_factory.h" 10 #include "chrome/browser/chrome_to_mobile_service_factory.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // We caught a close so we don't need to observe further notifications. 90 // We caught a close so we don't need to observe further notifications.
91 bridge_.reset(NULL); 91 bridge_.reset(NULL);
92 [progressAnimation_ stopAnimation]; 92 [progressAnimation_ stopAnimation];
93 // Cancel any delayed requests that may still be pending (close, etc.). 93 // Cancel any delayed requests that may still be pending (close, etc.).
94 [NSObject cancelPreviousPerformRequestsWithTarget:self]; 94 [NSObject cancelPreviousPerformRequestsWithTarget:self];
95 [super windowWillClose:notification]; 95 [super windowWillClose:notification];
96 } 96 }
97 97
98 // Override -[BaseBubbleController showWindow:] to set up UI elements. 98 // Override -[BaseBubbleController showWindow:] to set up UI elements.
99 - (void)showWindow:(id)sender { 99 - (void)showWindow:(id)sender {
100 DCHECK(service_->HasMobiles());
100 service_->LogMetric(ChromeToMobileService::BUBBLE_SHOWN); 101 service_->LogMetric(ChromeToMobileService::BUBBLE_SHOWN);
101 102
102 // Force load the NIB. 103 // Force load the NIB.
103 NSWindow* window = [self window]; 104 NSWindow* window = [self window];
104 105
105 // Get the list of mobile devices. 106 const ListValue* mobiles = service_->GetMobiles();
106 const ListValue& mobiles = service_->mobiles();
107 DCHECK(!mobiles.empty());
108 DictionaryValue* mobile = NULL; 107 DictionaryValue* mobile = NULL;
109 string16 name; 108 string16 name;
110 109
111 if (mobiles.GetSize() == 1) { 110 if (mobiles->GetSize() == 1) {
112 // Set the single device title; it's for multiple devices by default. 111 // Set the single device title; it's for multiple devices by default.
113 if (mobiles.GetDictionary(0, &mobile) && mobile->GetString("name", &name)) { 112 if (mobiles->GetDictionary(0, &mobile) &&
113 mobile->GetString("name", &name)) {
114 NSString* title = l10n_util::GetNSStringF( 114 NSString* title = l10n_util::GetNSStringF(
115 IDS_CHROME_TO_MOBILE_BUBBLE_SINGLE_TITLE, name); 115 IDS_CHROME_TO_MOBILE_BUBBLE_SINGLE_TITLE, name);
116 [title_ setStringValue:title]; 116 [title_ setStringValue:title];
117 } else { 117 } else {
118 NOTREACHED(); 118 NOTREACHED();
119 } 119 }
120 } else { 120 } else {
121 // Initialize the mobile device radio buttons. 121 // Initialize the mobile device radio buttons.
122 [mobileRadioGroup_ renewRows:mobiles.GetSize() columns:1]; 122 [mobileRadioGroup_ renewRows:mobiles->GetSize() columns:1];
123 NSArray* cellArray = [mobileRadioGroup_ cells]; 123 NSArray* cellArray = [mobileRadioGroup_ cells];
124 for (size_t i = 0; i < mobiles.GetSize(); ++i) { 124 for (size_t i = 0; i < mobiles->GetSize(); ++i) {
125 if (mobiles.GetDictionary(i, &mobile) && mobile->GetString("name", &name)) 125 if (mobiles->GetDictionary(i, &mobile) &&
126 mobile->GetString("name", &name)) {
126 [[cellArray objectAtIndex:i] setTitle:SysUTF16ToNSString(name)]; 127 [[cellArray objectAtIndex:i] setTitle:SysUTF16ToNSString(name)];
127 else 128 } else {
128 NOTREACHED(); 129 NOTREACHED();
130 }
129 } 131 }
130 [mobileRadioGroup_ setEnabled:YES]; 132 [mobileRadioGroup_ setEnabled:YES];
131 [mobileRadioGroup_ setHidden:NO]; 133 [mobileRadioGroup_ setHidden:NO];
132 [mobileRadioGroup_ sizeToCells]; 134 [mobileRadioGroup_ sizeToCells];
133 135
134 // Adjust the window size to accommodate the radio group. 136 // Adjust the window size to accommodate the radio group.
135 CGFloat deltaY = [mobileRadioGroup_ frame].size.height + kVerticalPadding; 137 CGFloat deltaY = [mobileRadioGroup_ frame].size.height + kVerticalPadding;
136 NSRect windowFrame = [window frame]; 138 NSRect windowFrame = [window frame];
137 windowFrame.size.height += deltaY; 139 windowFrame.size.height += deltaY;
138 [window setFrame:windowFrame display:YES animate:NO]; 140 [window setFrame:windowFrame display:YES animate:NO];
(...skipping 30 matching lines...) Expand all
169 [super showWindow:sender]; 171 [super showWindow:sender];
170 } 172 }
171 173
172 - (IBAction)learn:(id)sender { 174 - (IBAction)learn:(id)sender {
173 service_->LearnMore(browser_); 175 service_->LearnMore(browser_);
174 [self close]; 176 [self close];
175 } 177 }
176 178
177 - (IBAction)send:(id)sender { 179 - (IBAction)send:(id)sender {
178 // TODO(msw): Handle updates to the mobile list while the bubble is open. 180 // TODO(msw): Handle updates to the mobile list while the bubble is open.
179 const ListValue& mobiles = service_->mobiles(); 181 const ListValue* mobiles = service_->GetMobiles();
180 // |mobileRadioGroup_| has a single row by defualt, so these always match. 182 // |mobileRadioGroup_| has a single row by defualt, so these always match.
181 DCHECK_EQ(static_cast<NSInteger>(mobiles.GetSize()), 183 DCHECK_EQ(static_cast<NSInteger>(mobiles->GetSize()),
182 [mobileRadioGroup_ numberOfRows]); 184 [mobileRadioGroup_ numberOfRows]);
183 // NSMatrix selectedRow is -1 by default (in the single mobile device case). 185 // NSMatrix selectedRow is -1 by default (in the single mobile device case).
184 const int selected_index = std::max<int>([mobileRadioGroup_ selectedRow], 0); 186 const int selected_index = std::max<int>([mobileRadioGroup_ selectedRow], 0);
185 187
186 DictionaryValue* mobile = NULL; 188 DictionaryValue* mobile = NULL;
187 if (mobiles.GetDictionary(selected_index, &mobile)) { 189 if (mobiles->GetDictionary(selected_index, &mobile)) {
188 service_->SendToMobile(*mobile, 190 service_->SendToMobile(*mobile,
189 ([sendCopy_ state] == NSOnState) ? snapshotPath_ : FilePath(), 191 ([sendCopy_ state] == NSOnState) ? snapshotPath_ : FilePath(),
190 browser_, bridge_->AsWeakPtr()); 192 browser_, bridge_->AsWeakPtr());
191 } else { 193 } else {
192 NOTREACHED(); 194 NOTREACHED();
193 } 195 }
194 196
195 // Update the bubble's contents to show the "Sending..." progress animation. 197 // Update the bubble's contents to show the "Sending..." progress animation.
196 [cancel_ setEnabled:NO]; 198 [cancel_ setEnabled:NO];
197 [send_ setEnabled:NO]; 199 [send_ setEnabled:NO];
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 287
286 - (void)setSendCopy:(bool)sendCopy { 288 - (void)setSendCopy:(bool)sendCopy {
287 [sendCopy_ setState:(sendCopy ? NSOnState : NSOffState)]; 289 [sendCopy_ setState:(sendCopy ? NSOnState : NSOffState)];
288 } 290 }
289 291
290 - (ChromeToMobileBubbleNotificationBridge*)bridge { 292 - (ChromeToMobileBubbleNotificationBridge*)bridge {
291 return bridge_.get(); 293 return bridge_.get();
292 } 294 }
293 295
294 @end // ChromeToMobileBubbleController (JustForTesting) 296 @end // ChromeToMobileBubbleController (JustForTesting)
OLDNEW
« no previous file with comments | « chrome/browser/prefs/browser_prefs.cc ('k') | chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698