| 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/ui/sync/one_click_signin_helper.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 // We have to delay the cleaning until the new URL has finished loading because | 463 // We have to delay the cleaning until the new URL has finished loading because |
| 464 // we're not allowed to remove the last-loaded URL from the history. Objects | 464 // we're not allowed to remove the last-loaded URL from the history. Objects |
| 465 // of this type automatically self-destruct once they're finished their work. | 465 // of this type automatically self-destruct once they're finished their work. |
| 466 class CurrentHistoryCleaner : public content::WebContentsObserver { | 466 class CurrentHistoryCleaner : public content::WebContentsObserver { |
| 467 public: | 467 public: |
| 468 explicit CurrentHistoryCleaner(content::WebContents* contents); | 468 explicit CurrentHistoryCleaner(content::WebContents* contents); |
| 469 virtual ~CurrentHistoryCleaner(); | 469 virtual ~CurrentHistoryCleaner(); |
| 470 | 470 |
| 471 // content::WebContentsObserver: | 471 // content::WebContentsObserver: |
| 472 virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE; | 472 virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE; |
| 473 virtual void DidStopLoading( | 473 virtual void DidNavigateMainFrame( |
| 474 content::RenderViewHost* render_view_host) OVERRIDE; | 474 const content::LoadCommittedDetails& details, |
| 475 const content::FrameNavigateParams& params) OVERRIDE; |
| 475 | 476 |
| 476 private: | 477 private: |
| 477 scoped_ptr<content::WebContents> contents_; | 478 scoped_ptr<content::WebContents> contents_; |
| 478 int history_index_to_remove_; | 479 int history_index_to_remove_; |
| 479 | 480 |
| 480 DISALLOW_COPY_AND_ASSIGN(CurrentHistoryCleaner); | 481 DISALLOW_COPY_AND_ASSIGN(CurrentHistoryCleaner); |
| 481 }; | 482 }; |
| 482 | 483 |
| 483 CurrentHistoryCleaner::CurrentHistoryCleaner(content::WebContents* contents) | 484 CurrentHistoryCleaner::CurrentHistoryCleaner(content::WebContents* contents) |
| 484 : WebContentsObserver(contents) { | 485 : WebContentsObserver(contents) { |
| 485 history_index_to_remove_ = | 486 history_index_to_remove_ = |
| 486 web_contents()->GetController().GetLastCommittedEntryIndex(); | 487 web_contents()->GetController().GetLastCommittedEntryIndex(); |
| 487 } | 488 } |
| 488 | 489 |
| 489 CurrentHistoryCleaner::~CurrentHistoryCleaner() { | 490 CurrentHistoryCleaner::~CurrentHistoryCleaner() { |
| 490 } | 491 } |
| 491 | 492 |
| 492 void CurrentHistoryCleaner::DidStopLoading( | 493 void CurrentHistoryCleaner::DidNavigateMainFrame( |
| 493 content::RenderViewHost* render_view_host) { | 494 const content::LoadCommittedDetails& details, |
| 495 const content::FrameNavigateParams& params) { |
| 494 content::NavigationController* nc = &web_contents()->GetController(); | 496 content::NavigationController* nc = &web_contents()->GetController(); |
| 495 // Have to wait until something else gets added to history before removal. | 497 // Have to wait until something else gets added to history before removal. |
| 496 if (history_index_to_remove_ < nc->GetLastCommittedEntryIndex()) { | 498 if (history_index_to_remove_ < nc->GetLastCommittedEntryIndex()) { |
| 497 nc->RemoveEntryAtIndex(history_index_to_remove_); | 499 if (nc->RemoveEntryAtIndex(history_index_to_remove_)) |
| 498 delete this; // Success. | 500 delete this; // Success. |
| 499 } | 501 } |
| 500 } | 502 } |
| 501 | 503 |
| 502 void CurrentHistoryCleaner::WebContentsDestroyed( | 504 void CurrentHistoryCleaner::WebContentsDestroyed( |
| 503 content::WebContents* contents) { | 505 content::WebContents* contents) { |
| 504 delete this; // Failure. | 506 delete this; // Failure. |
| 505 } | 507 } |
| 506 | 508 |
| 507 void CloseTab(content::WebContents* tab) { | 509 void CloseTab(content::WebContents* tab) { |
| 508 Browser* browser = chrome::FindBrowserWithWebContents(tab); | 510 Browser* browser = chrome::FindBrowserWithWebContents(tab); |
| (...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 content::Referrer(), | 1314 content::Referrer(), |
| 1313 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1315 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 1314 std::string()); | 1316 std::string()); |
| 1315 } | 1317 } |
| 1316 } | 1318 } |
| 1317 | 1319 |
| 1318 // Clear the redirect URL. | 1320 // Clear the redirect URL. |
| 1319 redirect_url_ = GURL(); | 1321 redirect_url_ = GURL(); |
| 1320 sync_service->RemoveObserver(this); | 1322 sync_service->RemoveObserver(this); |
| 1321 } | 1323 } |
| OLD | NEW |