<commit_before>// Copyright (c) 2012 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 "ui/message_center/notification_list.h"

#include "base/bind.h"
#include "base/logging.h"
#include "base/time.h"
#include "base/values.h"

namespace message_center {

const size_t NotificationList::kMaxVisibleMessageCenterNotifications = 100;
const size_t NotificationList::kMaxVisiblePopupNotifications = 2;

NotificationList::Notification::Notification() : is_read(false),
                                                 shown_as_popup(false) {
}

NotificationList::Notification::~Notification() {
}

NotificationList::NotificationList(Delegate* delegate)
    : delegate_(delegate),
      message_center_visible_(false),
      unread_count_(0),
      quiet_mode_(false) {
}

NotificationList::~NotificationList() {
}

void NotificationList::SetMessageCenterVisible(bool visible) {
  if (message_center_visible_ == visible)
    return;
  message_center_visible_ = visible;
  if (!visible) {
    // When the list is hidden, clear the unread count, and mark all
    // notifications as read and shown.
    unread_count_ = 0;
    for (NotificationMap::iterator mapiter = notifications_.begin();
         mapiter != notifications_.end(); ++mapiter) {
      for (Notifications::iterator iter = mapiter->second.begin();
           iter != mapiter->second.end(); ++iter) {
        iter->is_read = true;
        iter->shown_as_popup = true;
      }
    }
  }
}

void NotificationList::AddNotification(
    ui::notifications::NotificationType type,
    const std::string& id,
    const string16& title,
    const string16& message,
    const string16& display_source,
    const std::string& extension_id,
    const DictionaryValue* optional_fields) {
  Notification notification;
  notification.type = type;
  notification.id = id;
  notification.title = title;
  notification.message = message;
  notification.display_source = display_source;
  notification.extension_id = extension_id;

  // Initialize primitive fields before unpacking optional fields.
  // timestamp initializes to default NULL time.<commit_msg>Marks notifications as shown slightly earlier for message center.<commit_after>// Copyright (c) 2012 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 "ui/message_center/notification_list.h"

#include "base/bind.h"
#include "base/logging.h"
#include "base/time.h"
#include "base/values.h"

namespace message_center {

const size_t NotificationList::kMaxVisibleMessageCenterNotifications = 100;
const size_t NotificationList::kMaxVisiblePopupNotifications = 2;

NotificationList::Notification::Notification() : is_read(false),
                                                 shown_as_popup(false) {
}

NotificationList::Notification::~Notification() {
}

NotificationList::NotificationList(Delegate* delegate)
    : delegate_(delegate),
      message_center_visible_(false),
      unread_count_(0),
      quiet_mode_(false) {
}

NotificationList::~NotificationList() {
}

void NotificationList::SetMessageCenterVisible(bool visible) {
  if (message_center_visible_ == visible)
    return;
  message_center_visible_ = visible;
  // When the center appears, mark all notifications as shown, and
  // when the center is hidden, clear the unread count, and mark all
  // notifications as read.
  if (!visible)
    unread_count_ = 0;

  for (NotificationMap::iterator mapiter = notifications_.begin();
       mapiter != notifications_.end(); ++mapiter) {
    for (Notifications::iterator iter = mapiter->second.begin();
         iter != mapiter->second.end(); ++iter) {
      if (visible)
        iter->shown_as_popup = true;
      else
        iter->is_read = true;
    }
  }
}

void NotificationList::AddNotification(
    ui::notifications::NotificationType type,
    const std::string& id,
    const string16& title,
    const string16& message,
    const string16& display_source,
    const std::string& extension_id,
    const DictionaryValue* optional_fields) {
  Notification notification;
  notification.type = type;
  notification.id = id;
  notification.title = title;
  notification.message = message;
  notification.display_source = display_source;
  notification.extension_id = extension_id;

  // Initialize primitive fields before unpacking optional fields.
  // timestamp initializes to default NULL time.
{'fraction_non_alphanumeric': 0.10097216084843129, 'fraction_numerical': 0.007070260715863898, 'mean_word_length': 3.8940540540540542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4997153', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1216, 'n_words': 332}