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.
4
5#include "chrome/browser/ui/views/load_complete_listener.h"
6
7#include "base/logging.h"
8#include "content/public/browser/notification_service.h"
9#include "content/public/browser/notification_types.h"
10
11LoadCompleteListener::LoadCompleteListener(Delegate* delegate)
12    : delegate_(delegate) {
13  DCHECK(delegate);
14  // Register for notification of when initial page load is complete to ensure
15  // that we wait until start-up is complete before calling the callback.
16  registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
17                 content::NotificationService::AllSources());
18}
19
20LoadCompleteListener::~LoadCompleteListener() {
21  if (registrar_.IsRegistered(this,
22      content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
23      content::NotificationService::AllSources())) {
24    registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
25                      content::NotificationService::AllSources());
26  }
27}
28
29void LoadCompleteListener::Observe(
30    int type,
31    const content::NotificationSource& source,
32    const content::NotificationDetails& details) {
33  DCHECK_EQ(content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, type);
34
35  delegate_->OnLoadCompleted();
36  registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
37                    content::NotificationService::AllSources());
38}
39