<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/cros/screen_lock_library.h"

#include "base/basictypes.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/observer_list.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "content/browser/browser_thread.h"
#include "third_party/cros/chromeos_screen_lock.h"

namespace chromeos {

class ScreenLockLibraryImpl : public ScreenLockLibrary {
 public:
  ScreenLockLibraryImpl() {}

  ~ScreenLockLibraryImpl() {
    if (screen_lock_connection_)
      chromeos::DisconnectScreenLock(screen_lock_connection_);
  }

  void Init() {
    if (CrosLibrary::Get()->EnsureLoaded()) {
      screen_lock_connection_ =
          chromeos::MonitorScreenLock(&ScreenLockedHandler, this);
    }
  }

  void AddObserver(Observer* observer) {
    observers_.AddObserver(observer);
  }

  void RemoveObserver(Observer* observer) {
    observers_.RemoveObserver(observer);
  }

  void NotifyScreenLockRequested() {
    chromeos::NotifyScreenLockRequested();
  }

  void NotifyScreenLockCompleted() {
    chromeos::NotifyScreenLockCompleted();
  }

  void NotifyScreenUnlockRequested() {
    chromeos::NotifyScreenUnlockRequested();
  }

  void NotifyScreenUnlockCompleted() {
    chromeos::NotifyScreenUnlockCompleted();
  }

 private:
  static void ScreenLockedHandler(void* object, ScreenLockEvent event) {
    ScreenLockLibraryImpl* self = static_cast<ScreenLockLibraryImpl*>(object);
    switch (event) {
      case chromeos::LockScreen:
        self->LockScreen();
        break;
      case chromeos::UnlockScreen:
        self->UnlockScreen();
        break;
      case chromeos::UnlockScreenFailed:
        self->UnlockScreenFailed();
        break;
      default:
        NOTREACHED();
        break;
    }
  }

  void LockScreen() {
    // Make sure we run on UI thread.
    if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
      BrowserThread::PostTask(
          BrowserThread::UI, FROM_HERE,
          NewRunnableMethod(this, &ScreenLockLibraryImpl::LockScreen));
      return;
    }
    FOR_EACH_OBSERVER(Observer, observers_, LockScreen(this));
  }

  void UnlockScreen() {
    // Make sure we run on UI thread.
    if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
      BrowserThread::PostTask(
          BrowserThread::UI, FROM_HERE,
          NewRunnableMethod(this, &ScreenLockLibraryImpl::UnlockScreen));
      return;
    }
    FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen(this));
  }

  void UnlockScreenFailed() {
    // Make sure we run on UI thread.
    if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
      BrowserThread::PostTask(
          BrowserThread::UI, FROM_HERE,
          NewRunnableMethod(this, &ScreenLockLibraryImpl::UnlockScreenFailed));
      return;
    }
    FOR_EACH_OBSERVER(Observer, observers_, UnlockScreenFailed(this));
  }

  ObserverList<Observer> observers_;

  // A reference to the screen lock API.
  chromeos::ScreenLockConnection screen_lock_connection_;

  DISALLOW_COPY_AND_ASSIGN(ScreenLockLibraryImpl);
};

class ScreenLockLibraryStubImpl : public ScreenLockLibrary {
 public:
  ScreenLockLibraryStubImpl() {}
  ~ScreenLockLibraryStubImpl() {}
  void Init() {}
  void AddObserver(Observer* observer) {}
  void RemoveObserver(Observer* observer) {}
  void NotifyScreenLockRequested() {}
  void NotifyScreenLockCompleted() {}
  void NotifyScreenUnlockRequested() {}
  void NotifyScreenUnlockCompleted() {}
};

// static
ScreenLockLibrary* ScreenLockLibrary::GetImpl(bool stub) {
  ScreenLockLibrary* impl;
  if (stub)
    impl = new ScreenLockLibraryStubImpl();<commit_msg>cros: Add missing "virtual" and OVERRIDE to overridden virtual methods of ScreenLockLibrary.<commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/cros/screen_lock_library.h"

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/observer_list.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "content/browser/browser_thread.h"
#include "third_party/cros/chromeos_screen_lock.h"

namespace chromeos {

class ScreenLockLibraryImpl : public ScreenLockLibrary {
 public:
  ScreenLockLibraryImpl() {}

  virtual ~ScreenLockLibraryImpl() {
    if (screen_lock_connection_)
      chromeos::DisconnectScreenLock(screen_lock_connection_);
  }

  // Begin ScreenLockLibrary implementation.
  virtual void Init() OVERRIDE {
    if (CrosLibrary::Get()->EnsureLoaded()) {
      screen_lock_connection_ =
          chromeos::MonitorScreenLock(&ScreenLockedHandler, this);
    }
  }

  virtual void AddObserver(Observer* observer) OVERRIDE {
    observers_.AddObserver(observer);
  }

  virtual void RemoveObserver(Observer* observer) OVERRIDE {
    observers_.RemoveObserver(observer);
  }

  virtual void NotifyScreenLockRequested() OVERRIDE {
    chromeos::NotifyScreenLockRequested();
  }

  virtual void NotifyScreenLockCompleted() OVERRIDE {
    chromeos::NotifyScreenLockCompleted();
  }

  virtual void NotifyScreenUnlockRequested() OVERRIDE {
    chromeos::NotifyScreenUnlockRequested();
  }

  virtual void NotifyScreenUnlockCompleted() OVERRIDE {
    chromeos::NotifyScreenUnlockCompleted();
  }
  // End ScreenLockLibrary implementation.

 private:
  static void ScreenLockedHandler(void* object, ScreenLockEvent event) {
    ScreenLockLibraryImpl* self = static_cast<ScreenLockLibraryImpl*>(object);
    switch (event) {
      case chromeos::LockScreen:
        self->LockScreen();
        break;
      case chromeos::UnlockScreen:
        self->UnlockScreen();
        break;
      case chromeos::UnlockScreenFailed:
        self->UnlockScreenFailed();
        break;
      default:
        NOTREACHED();
        break;
    }
  }

  void LockScreen() {
    // Make sure we run on UI thread.
    if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
      BrowserThread::PostTask(
          BrowserThread::UI, FROM_HERE,
          NewRunnableMethod(this, &ScreenLockLibraryImpl::LockScreen));
      return;
    }
    FOR_EACH_OBSERVER(Observer, observers_, LockScreen(this));
  }

  void UnlockScreen() {
    // Make sure we run on UI thread.
    if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
      BrowserThread::PostTask(
          BrowserThread::UI, FROM_HERE,
          NewRunnableMethod(this, &ScreenLockLibraryImpl::UnlockScreen));
      return;
    }
    FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen(this));
  }

  void UnlockScreenFailed() {
    // Make sure we run on UI thread.
    if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
      BrowserThread::PostTask(
          BrowserThread::UI, FROM_HERE,
          NewRunnableMethod(this, &ScreenLockLibraryImpl::UnlockScreenFailed));
      return;
    }
    FOR_EACH_OBSERVER(Observer, observers_, UnlockScreenFailed(this));
  }

  ObserverList<Observer> observers_;

  // A reference to the screen lock API.
  chromeos::ScreenLockConnection screen_lock_connection_;

  DISALLOW_COPY_AND_ASSIGN(ScreenLockLibraryImpl);
};

class ScreenLockLibraryStubImpl : public ScreenLockLibrary {
 public:
  ScreenLockLibraryStubImpl() {}
  virtual ~ScreenLockLibraryStubImpl() {}
  virtual void Init() OVERRIDE {}
  virtual void AddObserver(Observer* observer) OVERRIDE {}
  virtual void RemoveObserver(Observer* observer) OVERRIDE {}
  virtual void NotifyScreenLockRequested() OVERRIDE {}
  virtual void NotifyScreenLockCompleted() OVERRIDE {}
  virtual void NotifyScreenUnlockRequested() OVERRIDE {}
  virtual void NotifyScreenUnlockCompleted() OVERRIDE {}
};

// static
ScreenLockLibrary* ScreenLockLibrary::GetImpl(bool stub) {
  ScreenLockLibrary* impl;
  if (stub)
    impl = new ScreenLockLibraryStubImpl();
{'fraction_non_alphanumeric': 0.1037230730917694, 'fraction_numerical': 0.0009961399576640518, 'mean_word_length': 4.185280826339574, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5758415', 'n_tokens_mistral': 2393, 'n_tokens_neox': 2308, 'n_words': 482}